diff --git a/hangman.c b/hangman.c index 1a565aa..9644390 100644 --- a/hangman.c +++ b/hangman.c @@ -5,20 +5,17 @@ /* Linux ncurses include */ #include #endif -#include "hangman.h" +#include "hangman.h" //includes time.h #include //atexit #include #include //tolower #include -#include //time(null) #include "prng.h" #include //usleep #include "figures.h" - - int main(int argc, char **argv) { const char *short_options = "w:hf:ct"; @@ -32,7 +29,6 @@ int main(int argc, char **argv) { int c, startscr = 1; /* Show startscreen by default */ char filename[255]; filename[0] = '\0'; - //while ( (c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1 ) /* Initialization */ initscr(); @@ -95,6 +91,7 @@ int main(int argc, char **argv) { void startGame(game_state *gs) { noecho(); /* Don't show the player input */ + time(&gs->startTime); while (checkWin(gs)) { updateScreen(gs); playerInput(gs); @@ -317,6 +314,7 @@ int checkWin(game_state *gs) { return 1; } else { /* game end: decide if game is won or lost */ + time(&gs->endTime); printGameStats(gs); return 0; } @@ -325,6 +323,9 @@ int checkWin(game_state *gs) { void printGameStats(game_state *gs) { //clear(); int i; + double diff; + diff = difftime(gs->endTime, gs->startTime); + for (i = 0; i < gs->maxx; i++) { mvprintw(gs->centery, i, " "); mvprintw(gs->centery + 1, i, " "); @@ -343,7 +344,7 @@ void printGameStats(game_state *gs) { result = (float)((gs->guesses - gs->moves) / 1); } - sprintf(message, "Wrong guesses: %i, right/wrong ratio: %.2f", gs->moves, result); + sprintf(message, "Wrong guesses: %i, right/wrong ratio: %.2f, time: %.2fsec", gs->moves, result, diff); mvprintw(gs->centery + 1, gs->centerx - (strlen(message) / 2), message); } diff --git a/hangman.h b/hangman.h index abe4965..d63a810 100644 --- a/hangman.h +++ b/hangman.h @@ -1,3 +1,8 @@ +#include + + + + /* Defined macros */ #define DEFAULTTRIES 6 #define MAXWORDLENGTH 100 @@ -21,6 +26,8 @@ typedef struct { char wrongCharacters[DEFAULTTRIES]; int trollEnabled; char *alphabet; + time_t startTime; + time_t endTime; } game_state; typedef struct word {