diff options
| author | Atsutane <atsutane@freethoughts.de> | 2009-05-07 12:25:04 +0200 |
|---|---|---|
| committer | Atsutane <atsutane@freethoughts.de> | 2009-05-07 12:25:04 +0200 |
| commit | 48b6c8d9d47d8e51d3123b0adb85f7c3917bbec2 (patch) | |
| tree | aaf52cd1aaabe704082c3d6245d354775fc7f84c /src/pong.c | |
| parent | db06e7686a2a567d61a007b65be7890d5fba3b77 (diff) | |
| download | pong-48b6c8d9d47d8e51d3123b0adb85f7c3917bbec2.tar.gz pong-48b6c8d9d47d8e51d3123b0adb85f7c3917bbec2.tar.bz2 | |
Added random seed for p2_ai and the played time to the statusbar.
Diffstat (limited to 'src/pong.c')
| -rw-r--r-- | src/pong.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -31,6 +31,7 @@ #include <time.h> #include <ncurses.h> #include <unistd.h> +#include <time.h> #define GAME_LOOP_DIVISOR 12 @@ -53,6 +54,7 @@ struct ball_data { struct game_data { unsigned int max_field_x; /* field size x */ unsigned int max_field_y; /* field size y */ + time_t time_played; struct player_data *p1; /* Player 1 */ struct player_data *p2; /* Player 2 */ struct ball_data *ball; /* Ball */ @@ -78,6 +80,10 @@ void draw_statusbar(struct game_data *gd) { mvprintw(gd->max_field_y, 0, "%02d", gd->p1->score); mvprintw(gd->max_field_y, + (gd->max_field_x/2)-10, + "%04d seconds played", + time(NULL) - gd->time_played); + mvprintw(gd->max_field_y, gd->max_field_x-1, "%02d", gd->p2->score); } @@ -154,6 +160,8 @@ struct game_data *init_game_data(void) { /* Fill items with the default data */ check_field_size(gd); + time(&gd->time_played); + gd->p1->x = 0; gd->p1->y = gd->max_field_y / 2; gd->p1->score = 0; @@ -501,6 +509,8 @@ int main(void) { cbreak(); /* No line buffering */ keypad(stdscr, TRUE); /* Activate keypad */ + srand(time(NULL)); /* Set random seed */ + clear(); winner = game(); clear(); |
