Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // I WANT TO PLAY WITH YOU
- // YOUR FRIEND, AI
- #include <stdio.h>
- #include <unistd.h>
- #include <curses.h>
- //#include <conio.h>
- void draw();
- void keypressed(char keyboard);
- int player_one_y = 13, player_two_y = 13;
- int ball_x = 4, ball_y = 13;
- int ball_direct_x = 1, ball_direct_y = -1;
- int score_one = 0, score_two = 0;
- WINDOW *win;
- int main() {
- win = initscr();
- noecho();
- nodelay(win, true);
- curs_set(0);
- // draw();
- while (score_one != 21 || score_two != 21) {
- char c = getch();
- keypressed(c);
- if (ball_x - 1 == 2 && ball_direct_x == -1) {
- if (ball_y >= player_one_y - 1 && ball_y <= player_one_y + 1) {
- ball_direct_x *= -1;
- } else {
- score_two += 1;
- ball_y = 13;
- ball_x = 3;
- player_one_y = 13;
- player_two_y = 13;
- ball_direct_x = 1;
- ball_direct_y = 1;
- }
- }
- if (ball_x + 1 == 77 && ball_direct_x == 1) {
- if (ball_y >= player_two_y - 1 && ball_y <= player_two_y + 1) {
- ball_direct_x *= -1;
- } else {
- score_one += 1;
- ball_y = 13;
- ball_x = 76;
- player_two_y = 13;
- player_one_y = 13;
- ball_direct_x = -1;
- ball_direct_y = -1;
- }
- }
- if (ball_y == 1 || ball_y == 23) {
- ball_direct_y *= -1;
- }
- ball_x += ball_direct_x;
- ball_y += ball_direct_y;
- draw();
- usleep(50000);
- }
- }
- void draw() {
- // move(0,0);
- // system("@cls||clear");
- printf("\33c\e[3J");
- for (int y = 0; y < 25; y++) {
- for (int x = 0; x < 80; x++) {
- if (y == 0 || y == 24)
- printf("%c", '-');
- else if (x == 0 || x == 79)
- printf("%c", '|');
- else if ((y <= (player_one_y + 1) && y >= player_one_y - 1) && x == 2)
- printf("%c", ']');
- else if (y == ball_y && x == ball_x)
- printf("%c", '*');
- else if ((y <= (player_two_y + 1) && y >= player_two_y - 1) && x == 77)
- printf("%c", '[');
- else
- printf("%c", ' ');
- }
- printf("\n");
- }
- printf("player 1 %d - %d player 2\n", score_one, score_two);
- }
- void keypressed(char keyboard) {
- if (keyboard == 'z' && player_one_y < 24) {
- player_one_y++;
- } else if (keyboard == 'a' && player_one_y > 3) {
- player_one_y--;
- } else if (keyboard == 'm' && player_two_y < 24) {
- player_two_y++;
- } else if (keyboard == 'k' && player_two_y > 3) {
- player_two_y--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement