From d8b150ea5417278034955404ed54d537ed47b064 Mon Sep 17 00:00:00 2001 From: Peter Wiebe Date: Tue, 6 Feb 2024 18:48:37 +0100 Subject: [PATCH] Commit 27 - gewonnen funktionalitt in hauptspiel einbinden --- src/main/c/hangman.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/c/hangman.c b/src/main/c/hangman.c index 25cb67d..d20711d 100644 --- a/src/main/c/hangman.c +++ b/src/main/c/hangman.c @@ -20,6 +20,7 @@ char eingabe_buchstabe(); void lade_secret_word(char* secret_word, int level, char* path); void show_letters(char secret_word[100], char guessed_letters[100]); int letter_in_secret_word(char guessed_letter, char secret_word[100]); +int has_won(char secret_word[100], char guessed_letters[100]); void protokoll(){ clear_screen(); @@ -176,7 +177,7 @@ void hauptSpiel(int level){ lade_secret_word(secret_word, level, path); - while (attempts < 6) { //um gewinnen erweitern + while (attempts < 6 && won == 0) { draw_hangman(attempts); show_letters(secret_word, guessed_letters); guessed_letter = eingabe_buchstabe(); @@ -187,7 +188,7 @@ void hauptSpiel(int level){ else { attempts++; } - //gewonnen erweitern + won = has_won(secret_word, guessed_letters); } } @@ -325,4 +326,20 @@ int letter_in_secret_word(char guessed_letter, char secret_word[100]){ } } return 1; +} + +int has_won(char secret_word[100], char guessed_letters[100]){ + int occured; + for (int i = 0; i < strlen(secret_word); i++){ + occured = 0; + for (int k = 0; k < strlen(guessed_letters); k++){ + if (secret_word[i] == guessed_letters[k]){ + occured = 1; + } + } + if (occured == 0){ + return 0; + } + } + return 1; } \ No newline at end of file