Changed linebreak; animateLineClear clears a given line with a little animation; Display the correct word on game win

This commit is contained in:
2017-05-23 20:23:00 +02:00
parent bc8560aec5
commit 72385eea81
2 changed files with 31 additions and 18 deletions

View File

@@ -329,12 +329,19 @@ void printGameStats(game_state *gs) {
int i, z; int i, z;
double diff; double diff;
diff = difftime(gs->endTime, gs->startTime); diff = difftime(gs->endTime, gs->startTime);
for (z = 0; z <= gs->wordRows; z++) { //<= takes the last row too if (!gs->trollEnabled) {
for (i = 0; i < gs->maxx; i++) { for (z = 0; z <= gs->wordRows; z++) { //<= takes the last row too
mvprintw(gs->centery + z, i, " "); for (i = 0; i < gs->maxx; i++) {
//mvprintw(gs->centery + 1, 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) { if (gs->moves >= gs->allowedMoves) {
mvprintw(gs->centery, gs->centerx - 10, "Game lost. Solution:"); mvprintw(gs->centery, gs->centerx - 10, "Game lost. Solution:");
mvprintw(gs->centery + 1, gs->centerx - (gs->wordLength / 2), gs->guessWord); 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); 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 + 1, gs->centerx - (strlen(message) / 2), message);
mvprintw(gs->centery + 2, gs->centerx - (gs->wordLength / 2), gs->guessWord);
} }
refresh(); refresh();
@@ -407,19 +415,7 @@ void trollHitScreen(game_state *gs, int hits) {
flash(); /* flash the screen */ flash(); /* flash the screen */
mvprintw(5, centerDiff(gs->centerx, strings[i]), strings[i]); mvprintw(5, centerDiff(gs->centerx, strings[i]), strings[i]);
refresh(); refresh();
/* sleep and vanish */ animateLineClear(gs, 5, i);
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, " ");
}
} }
} }
} }
@@ -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, " ");
}
}

View File

@@ -9,7 +9,7 @@
#define ALPHABET 26 #define ALPHABET 26
#define ALPHABET_NUM 36 #define ALPHABET_NUM 36
#define ANIM_DURATION 1 #define ANIM_DURATION 1
#define LINEBREAK 8 //Linebreak offset #define LINEBREAK 16 //Linebreak offset
/* Data structures */ /* Data structures */
typedef struct { typedef struct {
@@ -58,3 +58,4 @@ int centerDiff(int coordinate, char *str);
void readRandomLine(char *file, char *result); void readRandomLine(char *file, char *result);
void trollHitScreen(game_state *gs, int hits); void trollHitScreen(game_state *gs, int hits);
void drawFigure(game_state *gs, int drawNext); void drawFigure(game_state *gs, int drawNext);
void animateLineClear(game_state *gs, int line, int offsetMultiplier);