Browse Source

refactoring: Auslagern von Funktionalität um einen return-Wert für Test zu erhalten + Separieren der Variablendeklaration von guessWord und displayWord für erhöhte Übersichtlichkeit

remotes/origin/tim
fdai7727 11 months ago
parent
commit
b97858be05
  1. 14
      src/main/c/Tim/hangman.c

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

@ -6,6 +6,8 @@
#define LISTSIZE 10 #define LISTSIZE 10
#define MAX_WORD_LENGTH 30 #define MAX_WORD_LENGTH 30
char* getWordFromList(int);
int getParameters(int, char*);
char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { char wordlist[LISTSIZE][MAX_WORD_LENGTH] = {
"Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet", "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet",
@ -26,11 +28,12 @@ void hangman()
do do
{ {
char guessWord[MAX_WORD_LENGTH]; char guessWord[MAX_WORD_LENGTH];
char displayWord[MAX_WORD_LENGTH];
int length; int length;
strcpy(guessWord,wordlist[rand() % LISTSIZE]);
strcpy(guessWord,getWordFromList(rand() % LISTSIZE));
length = strlen(guessWord); length = strlen(guessWord);
printf("%s %d\n",guessWord, length); printf("%s %d\n",guessWord, length);
char displayWord[MAX_WORD_LENGTH];
for (int i = 0; i <= length; i++) for (int i = 0; i <= length; i++)
{ {
if(i<length) if(i<length)
@ -49,3 +52,10 @@ void hangman()
printf("%c\n", userSelection); printf("%c\n", userSelection);
}while(userSelection != '0'); }while(userSelection != '0');
} }
char* getWordFromList(int x)
{
return wordlist[x];
}
Loading…
Cancel
Save