Advertisement
HeroBaga

Untitled

Aug 15th, 2021
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 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(500000);
  28. }
  29.  
  30. }
  31.  
  32. void draw(){
  33. printf ("\33c\e[3J");
  34. for (int i = 0; i < 25; i++) {
  35. for (int j = 0; j < 80; j++) {
  36. if (i == 0 || i == 24)
  37. printf("%c", '-');
  38. else if (j == 0 || j == 79)
  39. printf("%c", '|');
  40. else if ((i <= (player_one_y + 1) && i >= player_one_y - 1) && j == 3)
  41. printf("%c", ']');
  42. else if (i == player_one_y && j == player_one_y)
  43. printf("%c", '*');
  44. else if (j == 39 || j == 40)
  45. printf("%c", '-');
  46. else if ((i <= (player_two_y + 1) && i >= player_two_y- 1) && j == 77)
  47. printf("%c", '[');
  48. else
  49. printf("%c", ' ');
  50. }
  51. printf("\n");
  52. }
  53. printf("player 1 %d - %d player 2\n", score_one, score_two);
  54. }
  55.  
  56. void keypressed(char keyboard){
  57. if (keyboard == 'z' && player_one_y < 24) {
  58. player_one_y++;
  59. } else if (keyboard == 'a' && player_one_y > 3) {
  60. player_one_y--;
  61. } else if (keyboard == 'm' && player_two_y < 24) {
  62. player_two_y++;
  63. } else if (keyboard == 'k' && player_two_y > 3) {
  64. player_two_y--;
  65. }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement