Advertisement
HeroBaga

Untitled

Aug 15th, 2021
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. // I WANT TO PLAY WITH YOU
  2. // YOUR FRIEND, AI
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <curses.h>
  6.  
  7. void draw();
  8.  
  9. void keypressed(char keyboard);
  10.  
  11. int player_one_y = 13, player_two_y = 13;
  12.  
  13. int score_one = 0, score_two=0;
  14.  
  15.  
  16. int main() {
  17. initscr();
  18. curs_set(0);
  19. noecho();
  20. nodelay(stdscr, TRUE);
  21. while(score_one !=21 && score_two !=21){
  22. char c = getch();
  23. keypressed(c);
  24.  
  25. draw();
  26.  
  27. usleep(50000);
  28. }
  29.  
  30. }
  31.  
  32. void draw(){
  33. for (int i = 0; i < 25; i++) {
  34. for (int j = 0; j < 80; j++) {
  35. if (i == 0 || i == 24)
  36. printf("%c", '-');
  37. else if (j == 0 || j == 79)
  38. printf("%c", '|');
  39. else if ((i <= (player_one_y + 1) && i >= player_one_y - 1) && j == 3)
  40. printf("%c", ']');
  41. else if (i == player_one_y && j == player_one_y)
  42. printf("%c", '*');
  43. else if (j == 39 || j == 40)
  44. printf("%c", '-');
  45. else if ((i <= (player_two_y + 1) && i >= player_two_y- 1) && j == 77)
  46. printf("%c", '[');
  47. else
  48. printf("%c", ' ');
  49. }
  50. printf("\n");
  51. }
  52. printf("player 1 %d - %d player 2\n", score_one, score_two);
  53. }
  54.  
  55. void keypressed(char keyboard){
  56. if (keyboard == 'z' && player_one_y < 24) {
  57. player_one_y++;
  58. } else if (keyboard == 'a' && player_one_y > 3) {
  59. player_one_y--;
  60. } else if (keyboard == 'm' && player_two_y < 24) {
  61. player_two_y++;
  62. } else if (keyboard == 'k' && player_two_y > 3) {
  63. player_two_y--;
  64. }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement