diff --git a/figures.h b/figures.h index d68bfba..73abbcd 100644 --- a/figures.h +++ b/figures.h @@ -1,18 +1,18 @@ -const char base_figure[6][8] = {{"======="},\ - {"I "},\ - {"I "},\ - {"I "},\ - {"I "},\ +const char base_figure[6][8] = {{"======="}, \ + {"I "}, \ + {"I "}, \ + {"I "}, \ + {"I "}, \ {"I\\ "}}; -const char figure[6][5] = {{" O "},\ - {" I "},\ - {"\\I "},\ - {"\\I/"},\ - {"/ "},\ +const char figure[6][5] = {{" O "}, \ + {" I "}, \ + {"\\I "}, \ + {"\\I/"}, \ + {"/ "}, \ {"/ \\"}}; /* This array represents the layers where the strings of the current stage(array index) should be printed*/ -const int stages[] = {0, 1, 1, 1, 2, 2}; \ No newline at end of file +const int stages[] = {0, 1, 1, 1, 2, 2}; diff --git a/hangman.c b/hangman.c index 6e37146..5eea398 100644 --- a/hangman.c +++ b/hangman.c @@ -84,7 +84,7 @@ int main(int argc, char **argv) { initGuessWord(gs, filename); initAlphabet(gs); drawAlphabet(gs, 0); - drawFigure(gs); + drawFigure(gs, 0); startGame(gs); getch(); @@ -278,7 +278,8 @@ int stackWrongCharacter(game_state *gs, char wrongchar) { if (!alreadyUsed) { gs->wrongCharacters[strlen(gs->wrongCharacters)] = wrongchar; drawAlphabet(gs, wrongchar); - return 1; + drawFigure(gs, 1); + return 1; } else { return 0; } @@ -374,12 +375,15 @@ void trollHitScreen(game_state *gs, int hits) { mvprintw(5, centerDiff(gs->centerx, strings[i]), strings[i]); refresh(); /* sleep and vanish */ - int j = 0, k = gs->maxx - 1; + int j = 0, k = gs->maxx, sec, usec; + sec = 1; + usec = (sec * 1000000) / gs->maxx; + for (j = 0; j <= gs->centerx; j++, k--) { mvprintw(5, j, "!"); mvprintw(5, k, "!"); refresh(); - usleep(8000); + usleep(usec); //8000 mvprintw(5, j, " "); mvprintw(5, k, " "); @@ -388,17 +392,24 @@ void trollHitScreen(game_state *gs, int hits) { } } -void drawFigure(game_state *gs) { +void drawFigure(game_state *gs, int drawNext) { int row = 6; - int length = 10; + int length = 8; int i; - static init = 0; - if (init) { - for (i = 0; i < row; i++) { - mvprintw(i, gs->maxx - length - 1, "%s", base_figure[i]); - } - init = 1; - } + static int state = 0; + if (!state) { + for (i = 0; i < row; i++) { + mvprintw(i, gs->maxx - length - 1, "%s", base_figure[i]); + } + state++; + } else { + /* Draw the stages */ + if (drawNext) { + mvprintw(stages[state - 1] + 1, gs->maxx - 4, "%s", figure[state - 1]); + state++; + } + } + } diff --git a/hangman.h b/hangman.h index a11125b..137587d 100644 --- a/hangman.h +++ b/hangman.h @@ -47,4 +47,4 @@ void showHelp(game_state *gs); int centerDiff(int coordinate, char *str); void readRandomLine(char *file, char *result); void trollHitScreen(game_state *gs, int hits); -void drawFigure(game_state *gs); \ No newline at end of file +void drawFigure(game_state *gs, int drawNext);