From b34388d74a2311aad19aa4ad6562acca2c96d1ba Mon Sep 17 00:00:00 2001 From: Atsutane Date: Tue, 5 May 2009 19:30:38 +0200 Subject: Fixed some small issues. --- src/pong.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/pong.c') 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); -- cgit v1.2.3-70-g09d2