aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2015-03-30 18:17:14 +0200
committerTomasz Kramkowski <tk@the-tk.com>2015-03-30 18:17:14 +0200
commitaed3ad200d66fc502ab4759ac832cd23e6804029 (patch)
treeae45317aa8571f79064ae248d9c9f146e02fead9
parent351527ef70b963b3c3aab1d7d0e59dc02c6c2e0f (diff)
downloadc-stuff-aed3ad200d66fc502ab4759ac832cd23e6804029.tar.gz
c-stuff-aed3ad200d66fc502ab4759ac832cd23e6804029.tar.xz
c-stuff-aed3ad200d66fc502ab4759ac832cd23e6804029.zip
Various fixes to hangman.c.
-rw-r--r--hangman.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/hangman.c b/hangman.c
index 10373e2..4cf4c16 100644
--- a/hangman.c
+++ b/hangman.c
@@ -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;
}