diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2015-03-30 18:17:14 +0200 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2015-03-30 18:17:14 +0200 |
commit | aed3ad200d66fc502ab4759ac832cd23e6804029 (patch) | |
tree | ae45317aa8571f79064ae248d9c9f146e02fead9 | |
parent | 351527ef70b963b3c3aab1d7d0e59dc02c6c2e0f (diff) | |
download | c-stuff-aed3ad200d66fc502ab4759ac832cd23e6804029.tar.gz c-stuff-aed3ad200d66fc502ab4759ac832cd23e6804029.tar.xz c-stuff-aed3ad200d66fc502ab4759ac832cd23e6804029.zip |
Various fixes to hangman.c.
-rw-r--r-- | hangman.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -53,32 +53,33 @@ int main(int argc, char **argv) c = toupper(c); if (guessed[c - 'A']) - continue; + goto print_state; if (!in_secret[c - 'A']) { bad_guesses++; - printf("Wrong!"); - continue; + printf("Wrong!\n"); + goto print_state; } guessed[c - 'A'] = true; + for (unsigned i = 0; i < ALPHABET_CHARS; i++) + if (in_secret[i] && !guessed[i]) + goto print_state; + + state = WIN; + + break; +print_state: for (size_t i = 0; i < length; i++) if (isalpha(secret[i]) && !guessed[secret[i] - 'A']) putchar('_'); else putchar(secret[i]); putchar('\n'); + printf("You have %d guesses left.\n", MAX_GUESS - bad_guesses); - for (unsigned i = 0; i < ALPHABET_CHARS; i++) - if (in_secret[i] && !guessed[i]) - goto cont; - - state = WIN; - - break; -cont: - if (bad_guesses > MAX_GUESS) { + if (bad_guesses >= MAX_GUESS) { state = LOSS; break; } |