Browse Source

Hinzufügen, dass der Hangman bei falschen Raten erweitert wird

remotes/origin/tim
fdai7727 11 months ago
parent
commit
5b256f172b
  1. 14
      src/main/c/Tim/hangman.c
  2. 2
      src/main/c/Tim/hangman.h

14
src/main/c/Tim/hangman.c

@ -84,11 +84,13 @@ void hangman()
{
char guessWord[MAX_WORD_LENGTH];
int length;
int countWrongGuess=0;
strcpy(guessWord,getWordFromList(rand() % LISTSIZE));
length = strlen(guessWord);
printf("%s %d\n",guessWord, length);
char displayWord[MAX_WORD_LENGTH];
drawHangman(countWrongGuess);
for (int i = 0; i <= length; i++)
{
if(i<length)
@ -100,7 +102,7 @@ void hangman()
displayWord[i] = '\0';
}
}
printf("%s\n", displayWord);
printf("\n\n%s\n", displayWord);
while(!wordGuessed(guessWord, displayWord))
{
@ -113,10 +115,11 @@ void hangman()
if(!letterGuessed(userSelection, guessWord, length, displayWord))
{
drawHangman();
countWrongGuess++;
}
changeLetter(userSelection, guessWord, length, displayWord);
printf("%s\n", displayWord);
drawHangman(countWrongGuess);
printf("\n\n%s\n", displayWord);
}
}while(userSelection != '0');
@ -215,8 +218,7 @@ void changeLetter(char x, char y[], int length, char ptr[])
}
}
void drawHangman()
void drawHangman(int x)
{
for(int i = 0; i<STAGENUM;i++)
printf("%s", hangmanStages[i]);
printf("%s", hangmanStages[x]);
}

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

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