Browse Source

Entfernen eines ungenutzten formalen Parameters bei Funktion letterGuessed() und Hinzufügen eines Counters, der die Anzahl der Restversuche angibt

remotes/origin/tim
fdai7727 11 months ago
parent
commit
f0b83f487f
  1. 7
      src/main/c/Tim/hangman.c
  2. 2
      src/main/c/Tim/hangman.h
  3. 12
      src/test/c/Tim/test_hangman.c

7
src/main/c/Tim/hangman.c

@ -113,9 +113,10 @@ void hangman()
break;
}
if(!letterGuessed(userSelection, guessWord, length, displayWord))
if(!letterGuessed(userSelection, guessWord, length))
{
countWrongGuess++;
printf("Der von dir getippte Buchstabe war falsch! Du hast noch %d Versuche.\n", 6-countWrongGuess);
}
changeLetter(userSelection, guessWord, length, displayWord);
drawHangman(countWrongGuess);
@ -152,7 +153,7 @@ bool wordGuessed(char x[], char y[])
}
bool letterGuessed(char x, char y[], int length, char ptr[])
bool letterGuessed(char x, char y[], int length)
{
int counter = 0;
for(int i = 0; i<length; i++) {
@ -174,7 +175,7 @@ bool letterGuessed(char x, char y[], int length, char ptr[])
}
if(counter>0)
{
printf("Dein gewaehlter Buchstabe %c war ein Treffer!\n", x);
printf("Dein gewaehlter Buchstabe %c war ein Treffer! Du hast noch %d Versuche.\n", x);
return true;
}
else

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

@ -5,7 +5,7 @@
void hangman();
char* getWordFromList(int);
bool wordGuessed(char[],char[]);
bool letterGuessed(char, char[], int, char[]);
bool letterGuessed(char, char[], int);
void changeLetter(char, char[], int, char[]);
void drawHangman(int);

12
src/test/c/Tim/test_hangman.c

@ -86,9 +86,8 @@ void test_letterGuessed_differentCaps_small_big()
char x ='F';
char y[] ="Kartoffel";
int length = 9;
char z[] ="_________";
//assert
TEST_ASSERT_TRUE(letterGuessed(x,y,length,z));
TEST_ASSERT_TRUE(letterGuessed(x,y,length));
}
void test_letterGuessed_differentCaps_big_small()
@ -97,9 +96,8 @@ void test_letterGuessed_differentCaps_big_small()
char x ='k';
char y[] ="Kartoffel";
int length = 9;
char z[] ="_________";
//assert
TEST_ASSERT_TRUE(letterGuessed(x,y,length,z));
TEST_ASSERT_TRUE(letterGuessed(x,y,length));
}
void test_letterGuessed_sameCaps_small()
{
@ -107,9 +105,8 @@ void test_letterGuessed_sameCaps_small()
char x ='f';
char y[] ="Kartoffel";
int length = 9;
char z[] ="_________";
//assert
TEST_ASSERT_TRUE(letterGuessed(x,y,length,z));
TEST_ASSERT_TRUE(letterGuessed(x,y,length));
}
void test_letterGuessed_sameCaps_big()
@ -118,8 +115,7 @@ void test_letterGuessed_sameCaps_big()
char x ='K';
char y[] ="Kartoffel";
int length = 9;
char z[] ="_________";
//assert
TEST_ASSERT_TRUE(letterGuessed(x,y,length,z));
TEST_ASSERT_TRUE(letterGuessed(x,y,length));
}
Loading…
Cancel
Save