Added simple animation to hit message
This commit is contained in:
55
hangman.c
55
hangman.c
@@ -33,6 +33,7 @@ int main(int argc, char **argv) {
|
|||||||
gs->moves = 0;
|
gs->moves = 0;
|
||||||
gs->guesses = 0;
|
gs->guesses = 0;
|
||||||
gs->trollEnabled = 0;
|
gs->trollEnabled = 0;
|
||||||
|
keypad(stdscr, FALSE);
|
||||||
|
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
while ( (c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1 ) {
|
while ( (c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1 ) {
|
||||||
@@ -172,28 +173,29 @@ void drawGuessWord(game_state *gs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int playerInput(game_state *gs) {
|
int playerInput(game_state *gs) {
|
||||||
char inp;
|
int inp;
|
||||||
int i, found = 0;
|
int i, found = 0;
|
||||||
inp = getch();
|
inp = getch();
|
||||||
|
if (inp != KEY_UP && inp != KEY_DOWN && inp != KEY_LEFT && inp != KEY_RIGHT) {
|
||||||
for (i = 0; i < gs->wordLength; i++) {
|
for (i = 0; i < gs->wordLength; i++) {
|
||||||
if (inp == gs->guessWord[i]) {
|
if (inp == gs->guessWord[i]) {
|
||||||
found++;
|
found++;
|
||||||
//break;
|
//break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (found) {
|
||||||
if (found) {
|
/* found a valid character */
|
||||||
/* found a valid character */
|
if (fillCurrentWord(gs, inp)) {
|
||||||
if (fillCurrentWord(gs, inp)) {
|
//gs->moves++;
|
||||||
//gs->moves++;
|
gs->guesses++;
|
||||||
gs->guesses++;
|
trollHitScreen(gs, found);
|
||||||
trollHitScreen(gs, found);
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
/* no valid character found */
|
||||||
/* no valid character found */
|
if (stackWrongCharacter(gs, inp)) {
|
||||||
if (stackWrongCharacter(gs, inp)) {
|
gs->moves++;
|
||||||
gs->moves++;
|
gs->guesses++;
|
||||||
gs->guesses++;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -298,7 +300,7 @@ void trollHitScreen(game_state *gs, int hits) {
|
|||||||
"Ultra Hit", "Monster Hit", "Rampage", \
|
"Ultra Hit", "Monster Hit", "Rampage", \
|
||||||
"Unstoppable", "Wicked sick", "Godlike"};
|
"Unstoppable", "Wicked sick", "Godlike"};
|
||||||
int selection[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
|
int selection[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||||
int i, len, z, found = 0;
|
int i, found = 0;
|
||||||
for (i = 0; i < 9; i++) {
|
for (i = 0; i < 9; i++) {
|
||||||
if (selection[i] == hits) {
|
if (selection[i] == hits) {
|
||||||
found = 1;
|
found = 1;
|
||||||
@@ -310,10 +312,15 @@ void trollHitScreen(game_state *gs, int hits) {
|
|||||||
mvprintw(5, centerDiff(gs->centerx, strings[i]), strings[i]);
|
mvprintw(5, centerDiff(gs->centerx, strings[i]), strings[i]);
|
||||||
refresh();
|
refresh();
|
||||||
/* sleep and vanish */
|
/* sleep and vanish */
|
||||||
usleep(500000);
|
int j = 0, k = gs->maxx - 1;
|
||||||
len = strlen(strings[i]);
|
for (j = 0; j < gs->centerx; j++, k--) {
|
||||||
for (z = centerDiff(gs->centerx, strings[i]); z < gs->centerx + len; z++) {
|
mvprintw(5, j, "!");
|
||||||
mvprintw(5, z, " ");
|
mvprintw(5, k, "!");
|
||||||
|
refresh();
|
||||||
|
usleep(8000);
|
||||||
|
mvprintw(5, j, " ");
|
||||||
|
mvprintw(5, k, " ");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user