From 72385eea810fab21d8cdae55d02a872797968222 Mon Sep 17 00:00:00 2001 From: structix Date: Tue, 23 May 2017 20:23:00 +0200 Subject: [PATCH] Changed linebreak; animateLineClear clears a given line with a little animation; Display the correct word on game win --- hangman.c | 46 +++++++++++++++++++++++++++++----------------- hangman.h | 3 ++- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/hangman.c b/hangman.c index 1183c3f..cde0413 100644 --- a/hangman.c +++ b/hangman.c @@ -329,12 +329,19 @@ void printGameStats(game_state *gs) { int i, z; double diff; diff = difftime(gs->endTime, gs->startTime); - for (z = 0; z <= gs->wordRows; z++) { //<= takes the last row too - for (i = 0; i < gs->maxx; i++) { - mvprintw(gs->centery + z, i, " "); - //mvprintw(gs->centery + 1, i, " "); + if (!gs->trollEnabled) { + for (z = 0; z <= gs->wordRows; z++) { //<= takes the last row too + for (i = 0; i < gs->maxx; i++) { + mvprintw(gs->centery + z, i, " "); + //mvprintw(gs->centery + 1, i, " "); + } + } + } else { + for (z = 0; z <= gs->wordRows; z++) { + animateLineClear(gs, gs->centery + z, -1); //-1 to speed up the animation } } + if (gs->moves >= gs->allowedMoves) { mvprintw(gs->centery, gs->centerx - 10, "Game lost. Solution:"); mvprintw(gs->centery + 1, gs->centerx - (gs->wordLength / 2), gs->guessWord); @@ -351,6 +358,7 @@ void printGameStats(game_state *gs) { 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); + mvprintw(gs->centery + 2, gs->centerx - (gs->wordLength / 2), gs->guessWord); } refresh(); @@ -407,19 +415,7 @@ void trollHitScreen(game_state *gs, int hits) { flash(); /* flash the screen */ mvprintw(5, centerDiff(gs->centerx, strings[i]), strings[i]); refresh(); - /* sleep and vanish */ - int j = 0, k = gs->maxx, usec; - usec = (ANIM_DURATION * 1000000 + (100000 * i)) / gs->maxx; - - for (j = 0; j <= gs->centerx; j++, k--) { - mvprintw(5, j, "!"); - mvprintw(5, k, "!"); - refresh(); - usleep(usec); - mvprintw(5, j, " "); - mvprintw(5, k, " "); - - } + animateLineClear(gs, 5, i); } } } @@ -443,3 +439,19 @@ void drawFigure(game_state *gs, int drawNext) { } } +void animateLineClear(game_state *gs, int line, int offsetMultiplier) { + /* sleep and vanish */ + int j = 0, k = gs->maxx, usec; + usec = (ANIM_DURATION * 1000000 + (100000 * offsetMultiplier)) / gs->maxx; + + for (j = 0; j <= gs->centerx; j++, k--) { + mvprintw(line, j, "!"); + mvprintw(line, k, "!"); + refresh(); + usleep(usec); + mvprintw(line, j, " "); + mvprintw(line, k, " "); + } +} + + diff --git a/hangman.h b/hangman.h index c2b9e6f..7e2bd37 100644 --- a/hangman.h +++ b/hangman.h @@ -9,7 +9,7 @@ #define ALPHABET 26 #define ALPHABET_NUM 36 #define ANIM_DURATION 1 -#define LINEBREAK 8 //Linebreak offset +#define LINEBREAK 16 //Linebreak offset /* Data structures */ typedef struct { @@ -58,3 +58,4 @@ int centerDiff(int coordinate, char *str); void readRandomLine(char *file, char *result); void trollHitScreen(game_state *gs, int hits); void drawFigure(game_state *gs, int drawNext); +void animateLineClear(game_state *gs, int line, int offsetMultiplier);