diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 0f7c94d..9af39d7 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -3,6 +3,7 @@ #include #include #include +#include #define LISTSIZE 10 #define MAX_WORD_LENGTH 30 @@ -46,9 +47,13 @@ void hangman() } printf("%s\n", displayWord); - printf("Bitte gib einen Buchstaben ein!\n"); - scanf(" %c", &userSelection); - printf("%c\n", userSelection); + while(!wordGuessed(guessWord, displayWord)) + { + printf("Bitte gib einen Buchstaben ein!\n"); + scanf(" %c", &userSelection); + printf("%c\n", userSelection); + } + }while(userSelection != '0'); } @@ -65,3 +70,14 @@ char* getWordFromList(int x) } } +bool wordGuessed(char x[], char y[]) +{ + if(strcmp(x,y) == 0) + { + return true; + } + else + { + return false; + } +} \ No newline at end of file diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index 0995129..d3160df 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -1,7 +1,9 @@ +#include #ifndef HANGMAN_H #define HANGMAN_H void hangman(); char* getWordFromList(int); +bool wordGuessed(char[],char[]); #endif diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index 074a1c5..dc449e0 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -1,6 +1,7 @@ #include "hangman.h" #include "unity.h" #include +#include @@ -49,4 +50,25 @@ void test_getWordFromList_IndexOutOfList() strcpy(actualResult,getWordFromList(pos)); //assert TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult); -} \ No newline at end of file +} + +void test_wonGame_wordGuessed() +{ + //arrange + char word1[] ="Kartoffel"; + char word2[] = "Kartoffel"; + //assert + TEST_ASSERT_TRUE(wordGuessed(word1, word2)); +} + +void test_not_wordGuessed() +{ + //arrange + char word1[] ="Kartoffel"; + char word2[] ="Thunfisch"; + //assert + TEST_ASSERT_FALSE(wordGuessed(word1, word2)); +} + + +