From ccf87e12cf994d48dc2702ef84bf34c4fa7043fc Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 20:52:12 +0100 Subject: [PATCH] Einbau der Abbruchbedingung bei zu viel falschen Tipps --- src/main/c/Tim/hangman.c | 25 ++++++++++++++++++------- src/main/c/Tim/hangman.h | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 1a52a87..ab0255d 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -104,20 +104,20 @@ void hangman() } printf("\n\n%s\n", displayWord); - while(!wordGuessed(guessWord, displayWord)) + while(1) { printf("Bitte gib einen Buchstaben ein!\n"); scanf(" %c", &userSelection); - if(userSelection == '0') - { - break; - } if(!letterGuessed(userSelection, guessWord, length)) { countWrongGuess++; printf("Der von dir getippte Buchstabe war falsch! Du hast noch %d Versuche.\n", 6-countWrongGuess); } + if(userSelection == '0'||wordGuessed(guessWord, displayWord)||noTrysLeft(countWrongGuess)) + { + break; + } changeLetter(userSelection, guessWord, length, displayWord); drawHangman(countWrongGuess); printf("\n\n%s\n", displayWord); @@ -152,7 +152,6 @@ bool wordGuessed(char x[], char y[]) } } - bool letterGuessed(char x, char y[], int length) { int counter = 0; @@ -185,7 +184,6 @@ bool letterGuessed(char x, char y[], int length) } - void changeLetter(char x, char y[], int length, char ptr[]) { for(int i = 0; i