ANIM_DURATION added #12; ASCII Hangman finished, reduced tries to 5

This commit is contained in:
2017-05-05 21:06:53 +02:00
parent d0eae536a7
commit 73a36e65b7
2 changed files with 15 additions and 9 deletions

View File

@@ -88,6 +88,7 @@ int main(int argc, char **argv) {
startGame(gs);
getch();
clear();
free(gs);
return 0;
}
@@ -116,10 +117,10 @@ void showStartScreen(game_state *gs) {
}
void updateScreen(game_state *gs) {
mvprintw(1, 1, "Remaining wrong guesses: %i", (gs->allowedMoves - gs->moves));
mvprintw(0, 1, "Remaining wrong guesses: %i", (gs->allowedMoves - gs->moves));
mvprintw(gs->maxy - 1, 1, "Press ctrl + c to exit.");
drawGuessWord(gs);
mvprintw(2, 1, "Wrong characters: %s", gs->wrongCharacters);
mvprintw(1, 1, "Wrong characters: %s", gs->wrongCharacters);
refresh();
}
@@ -133,7 +134,7 @@ void initCoordinates(game_state *gs) {
void initGuessWord(game_state *gs, char *filename) {
int i;
mvprintw(1, 1, "Please enter your word: ");
mvprintw(0, 1, "Please enter your word: ");
if (strlen(gs->guessWord) == 0) { /* Word can be set by arguments */
if (strlen(filename) == 0) {
/* Manual input */
@@ -297,7 +298,12 @@ int checkWin(game_state *gs) {
}
void printGameStats(game_state *gs) {
clear();
//clear();
int i;
for (i = 0; i < gs->maxx; i++) {
mvprintw(gs->centery, i, " ");
mvprintw(gs->centery + 1, i, " ");
}
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);
@@ -375,15 +381,14 @@ 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, sec, usec;
sec = 1;
usec = (sec * 1000000) / gs->maxx;
int j = 0, k = gs->maxx, usec;
usec = (ANIM_DURATION * 1000000) / gs->maxx;
for (j = 0; j <= gs->centerx; j++, k--) {
mvprintw(5, j, "!");
mvprintw(5, k, "!");
refresh();
usleep(usec); //8000
usleep(usec);
mvprintw(5, j, " ");
mvprintw(5, k, " ");

View File

@@ -1,8 +1,9 @@
/* Defined macros */
#define DEFAULTTRIES 9
#define DEFAULTTRIES 6
#define MAXWORDLENGTH 100
#define ALPHABET 26
#define ALPHABET_NUM 36
#define ANIM_DURATION 1
/* Data structures */
typedef struct {