Changed linebreak; animateLineClear clears a given line with a little animation; Display the correct word on game win
This commit is contained in:
38
hangman.c
38
hangman.c
@@ -329,12 +329,19 @@ void printGameStats(game_state *gs) {
|
||||
int i, z;
|
||||
double diff;
|
||||
diff = difftime(gs->endTime, gs->startTime);
|
||||
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, " ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user