#7 use last word in case the hits are higher
This commit is contained in:
14
hangman.c
14
hangman.c
@@ -258,7 +258,7 @@ void printGameStats(game_state *gs) {
|
||||
sprintf(message, "Game won! Total guesses: %i", gs->guesses);
|
||||
mvprintw(gs->centery, gs->centerx - (strlen(message) / 2), message);
|
||||
sprintf(message, "Wrong guesses: %i, right/wrong ratio: %.2f", gs->moves, (float)(gs->guesses - gs->moves) / gs->moves);
|
||||
mvprintw(gs->centery, gs->centerx - (strlen(message) / 2), message);
|
||||
mvprintw(gs->centery + 1, gs->centerx - (strlen(message) / 2), message);
|
||||
|
||||
}
|
||||
refresh();
|
||||
@@ -281,15 +281,19 @@ void readRandomLine(char *file, char *result) {
|
||||
long totalLength = 0, rand = 0;
|
||||
FILE *fp = fopen(file, "r");
|
||||
char c;
|
||||
|
||||
int wordlength = 0;
|
||||
|
||||
while ((c = fgetc(fp)) != EOF) {
|
||||
if (c == '\n') ++totalLength;
|
||||
}
|
||||
|
||||
rand = getrandom(0, totalLength);
|
||||
fseek(fp, rand, SEEK_SET);
|
||||
fseek(fp, -rand, SEEK_END);
|
||||
|
||||
fgets(result, MAXWORDLENGTH, fp);
|
||||
/* remove \n at the end of the line */
|
||||
wordlength = strlen(result);
|
||||
result[wordlength - 1] = '\0';
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
@@ -307,6 +311,10 @@ void trollHitScreen(game_state *gs, int hits) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hits > 10) {
|
||||
found = 1;
|
||||
i = 8;
|
||||
}
|
||||
if (found) {
|
||||
flash(); /* flash the screen */
|
||||
mvprintw(5, centerDiff(gs->centerx, strings[i]), strings[i]);
|
||||
|
Reference in New Issue
Block a user