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>
- void draw();
- void keypressed(char keyboard);
- int player_one_y = 13, player_two_y = 13;
- int score_one = 0, score_two=0;
- int main() {
- initscr();
- curs_set(0);
- noecho();
- nodelay(stdscr, TRUE);
- while(score_one !=21 && score_two !=21){
- char c = getch();
- keypressed(c);
- draw();
- usleep(50000);
- }
- }
- void draw(){
- for (int i = 0; i < 25; i++) {
- for (int j = 0; j < 80; j++) {
- if (i == 0 || i == 24)
- printf("%c", '-');
- else if (j == 0 || j == 79)
- printf("%c", '|');
- else if ((i <= (player_one_y + 1) && i >= player_one_y - 1) && j == 3)
- printf("%c", ']');
- else if (i == player_one_y && j == player_one_y)
- printf("%c", '*');
- else if (j == 39 || j == 40)
- printf("%c", '-');
- else if ((i <= (player_two_y + 1) && i >= player_two_y- 1) && j == 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