Browse Source

Einbauen Abbruchbedingung, dass das Wort erraten wurde + Hinzufügen der Testfälle für ungleich und gleich

remotes/origin/tim
fdai7727 11 months ago
parent
commit
b2b0190cba
  1. 22
      src/main/c/Tim/hangman.c
  2. 2
      src/main/c/Tim/hangman.h
  3. 24
      src/test/c/Tim/test_hangman.c

22
src/main/c/Tim/hangman.c

@ -3,6 +3,7 @@
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#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;
}
}

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

@ -1,7 +1,9 @@
#include <stdbool.h>
#ifndef HANGMAN_H
#define HANGMAN_H
void hangman();
char* getWordFromList(int);
bool wordGuessed(char[],char[]);
#endif

24
src/test/c/Tim/test_hangman.c

@ -1,6 +1,7 @@
#include "hangman.h"
#include "unity.h"
#include <string.h>
#include <stdbool.h>
@ -49,4 +50,25 @@ void test_getWordFromList_IndexOutOfList()
strcpy(actualResult,getWordFromList(pos));
//assert
TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult);
}
}
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));
}
Loading…
Cancel
Save