aboutsummaryrefslogtreecommitdiff
path: root/src/pong.c
diff options
context:
space:
mode:
authorAtsutane <atsutane@freethoughts.de>2009-05-05 19:30:38 +0200
committerAtsutane <atsutane@freethoughts.de>2009-05-05 19:30:38 +0200
commitb34388d74a2311aad19aa4ad6562acca2c96d1ba (patch)
tree4e028e220d0c585e0494078b5230b5774c9f3ab7 /src/pong.c
parent8b856cae1fe70fb9663bbc80d9720d184792828e (diff)
downloadpong-b34388d74a2311aad19aa4ad6562acca2c96d1ba.tar.gz
pong-b34388d74a2311aad19aa4ad6562acca2c96d1ba.tar.bz2
Fixed some small issues.
Diffstat (limited to 'src/pong.c')
-rw-r--r--src/pong.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/pong.c b/src/pong.c
index 1411f82..5cf672c 100644
--- a/src/pong.c
+++ b/src/pong.c
@@ -361,7 +361,13 @@ int game(void) {
int p, r;
struct game_data *gd; /* contains all our data */
- gd = init_game_data();
+ if ((gd = init_game_data()) == NULL) {
+ mvprintw(0, 0, "Could not allocate memory for the game_data.");
+ timeout(-1);
+ getch();
+ return -1;
+ }
+
p=0;
clocks = clock();
interval = CLOCKS_PER_SEC/4;
@@ -372,6 +378,8 @@ int game(void) {
ball_movement(gd);
p2_ai(gd);
+ refresh();
+
while ((gd->p1->score != 21) &&
(gd->p2->score != 21)) {
if (clocks > clocks + interval) {
@@ -399,6 +407,7 @@ int game(void) {
draw_statusbar(gd);
p++;
+ clocks = clock();
refresh();
}
}
@@ -433,9 +442,15 @@ int main(void) {
nonl(); /* Receive \r instead of \n */
curs_set(0); /* Set Cursor invisible */
cbreak(); /* No line buffering */
- timeout(250); /* set input timeout to 250 milliseconds */
+ timeout(-1); /* set delay blocking */
keypad(stdscr, TRUE); /* Activate keypad */
+ mvprintw(0, 0, "Press a key to start.");
+ refresh();
+ getch();
+ clear();
+ timeout(0); /* set delay non blocking */
+
winner = game();
clear();
getmaxyx(stdscr, y, x);