Browse Source

Einbau der Abbruchbedingung bei zu viel falschen Tipps

remotes/origin/tim
fdai7727 11 months ago
parent
commit
ccf87e12cf
  1. 25
      src/main/c/Tim/hangman.c
  2. 1
      src/main/c/Tim/hangman.h

25
src/main/c/Tim/hangman.c

@ -104,20 +104,20 @@ void hangman()
} }
printf("\n\n%s\n", displayWord); printf("\n\n%s\n", displayWord);
while(!wordGuessed(guessWord, displayWord))
while(1)
{ {
printf("Bitte gib einen Buchstaben ein!\n"); printf("Bitte gib einen Buchstaben ein!\n");
scanf(" %c", &userSelection); scanf(" %c", &userSelection);
if(userSelection == '0')
{
break;
}
if(!letterGuessed(userSelection, guessWord, length)) if(!letterGuessed(userSelection, guessWord, length))
{ {
countWrongGuess++; countWrongGuess++;
printf("Der von dir getippte Buchstabe war falsch! Du hast noch %d Versuche.\n", 6-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); changeLetter(userSelection, guessWord, length, displayWord);
drawHangman(countWrongGuess); drawHangman(countWrongGuess);
printf("\n\n%s\n", displayWord); printf("\n\n%s\n", displayWord);
@ -152,7 +152,6 @@ bool wordGuessed(char x[], char y[])
} }
} }
bool letterGuessed(char x, char y[], int length) bool letterGuessed(char x, char y[], int length)
{ {
int counter = 0; 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[]) void changeLetter(char x, char y[], int length, char ptr[])
{ {
for(int i = 0; i<length; i++) { for(int i = 0; i<length; i++) {
@ -222,4 +220,17 @@ void changeLetter(char x, char y[], int length, char ptr[])
void drawHangman(int x) void drawHangman(int x)
{ {
printf("%s", hangmanStages[x]); printf("%s", hangmanStages[x]);
}
bool noTrysLeft(int x)
{
if(x == 6)
{
printf("Du hast verloren!\n\n");
return true;
}
else
{
return false;
}
} }

1
src/main/c/Tim/hangman.h

@ -8,5 +8,6 @@ bool wordGuessed(char[],char[]);
bool letterGuessed(char, char[], int); bool letterGuessed(char, char[], int);
void changeLetter(char, char[], int, char[]); void changeLetter(char, char[], int, char[]);
void drawHangman(int); void drawHangman(int);
bool noTrysLeft(int);
#endif #endif
Loading…
Cancel
Save