-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpong.c
executable file
·71 lines (69 loc) · 2.47 KB
/
pong.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <ncurses.h>
typedef struct{short int x, y, c; bool movhor, movver;} object;
main() {
object scr; int i = 0,cont=0; bool end=false;
initscr();
start_color();
init_pair(1,COLOR_BLUE,COLOR_BLACK);
keypad(stdscr,true);
noecho();
curs_set(0);
getmaxyx(stdscr,scr.y,scr.x);
object b1={scr.x-2,scr.y/2,0,false,false},b2={1,scr.y/2,0,false,false},b={scr.x/2,scr.y/2,0,false,false};
mvprintw(4,0,"\t oooooooooo \n"
"\t 888 888 ooooooo ooooooo oooooooo8 \n"
"\t 888oooo88 888 888 888 888 888 88o \n"
"\t 888 888 888 888 888 888oo888o \n"
"\t o888o 88ooo88 o888o o888o 888 888 \n"
"\t 888ooo888 \n\n"
"\t Any questions please send me at [email protected] \n"
"\t \t\t\tPlayer 1 your controls are 'a' and 'q' \n"
"\t \t\t\tPlayer 2 your controls are the arrows of the keyboard \n"
"\t \t\t\tPush ANY key to start, 'p' for pause and ESC to quit" );
getch();
for (nodelay(stdscr,1); !end; usleep(4000)) {
if (++cont%16==0){
if ((b.y==scr.y-1)||(b.y==1))
b.movver=!b.movver;
if ((b.x>=scr.x-2)||(b.x<=2)){
b.movhor=!b.movhor;
if ((b.y==b1.y-1)||(b.y==b2.y-1)) {
b.movver=false;
} else if ((b.y==b1.y+1)||(b.y==b2.y+1)) {
b.movver=true;
} else if ((b.y != b1.y) && (b.y != b2.y)) {
(b.x>=scr.x-2) ? b1.c++: b2.c++;
b.x=scr.x/2;
b.y=scr.y/2;
}
}
b.x=b.movhor ? b.x+1 : b.x-1;
b.y=b.movver ? b.y+1 : b.y-1;
if (b1.y<=1)
b1.y=scr.y-2;
if (b1.y>=scr.y-1)
b1.y=2;
if (b2.y<=1)
b2.y=scr.y-2;
if (b2.y>=scr.y-1)
b2.y=2;
}
switch (getch()) {
case KEY_DOWN: b1.y++; break;
case KEY_UP: b1.y--; break;
case 'q': b2.y--; break;
case 'a': b2.y++; break;
case 'p': getchar(); break;
case 0x1B: endwin(); end++; break;
}
erase();
mvprintw(2,scr.x/2-2,"%i | %i",b1.c,b2.c);
mvvline(0,scr.x/2,ACS_VLINE,scr.y);
attron(COLOR_PAIR(1));
mvprintw(b.y,b.x,"o");
for(i=-1;i<2;i++){
mvprintw(b1.y+i,b1.x,"|");
mvprintw(b2.y+i,b2.x,"|");}
attroff(COLOR_PAIR(1));
}
}