Advertisement
HeroBaga

Untitled

Aug 15th, 2021
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 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 ball_x = 4, ball_y = 13;
  14.  
  15. int score_one = 0, score_two=0;
  16.  
  17.  
  18. int main() {
  19. initscr();
  20. curs_set(0);
  21. noecho();
  22. nodelay(stdscr, TRUE);
  23. // while(score_one !=21 || score_two !=21){
  24. // char c = getch();
  25. // keypressed(c);
  26. //
  27. // draw();
  28. //
  29. // usleep(500000);
  30. // }
  31.  
  32. }
  33.  
  34. void draw(){
  35. // move(0,0);
  36. system("@cls||clear");
  37. for (int y = 0; y < 25; y++) {
  38. for (int x = 0; x < 80; x++) {
  39. if (y == 0 || y == 24)
  40. printf("%c", '-');
  41. else if (x == 0 || x == 79)
  42. printf("%c", '|');
  43. else if ((y <= (player_one_y + 1) && y >= player_one_y - 1) && x == 3)
  44. printf("%c", ']');
  45. else if (y == ball_y && x == ball_x)
  46. printf("%c", '*');
  47. else if (x == 39 || x == 40)
  48. printf("%c", '-');
  49. else if ((y <= (player_two_y + 1) && y >= player_two_y- 1) && x == 77)
  50. printf("%c", '[');
  51. else
  52. printf("%c", ' ');
  53. }
  54. printf("\n");
  55. }
  56. printf("player 1 %d - %d player 2\n", score_one, score_two);
  57. }
  58.  
  59. void keypressed(char keyboard){
  60. if (keyboard == 'z' && player_one_y < 24) {
  61. player_one_y++;
  62. } else if (keyboard == 'a' && player_one_y > 3) {
  63. player_one_y--;
  64. } else if (keyboard == 'm' && player_two_y < 24) {
  65. player_two_y++;
  66. } else if (keyboard == 'k' && player_two_y > 3) {
  67. player_two_y--;
  68. }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement