From c726d4f19acadfae274305ead298e8a330f9b6d4 Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 8 Feb 2024 23:07:19 +0100 Subject: [PATCH] adding difficulty to initialize (part two) --- src/main/c/Hangman/word_selector.c | 68 ++++++++++++++++++++++-------- src/main/c/main.c | 2 +- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/main/c/Hangman/word_selector.c b/src/main/c/Hangman/word_selector.c index 5b2b914..ff25adb 100644 --- a/src/main/c/Hangman/word_selector.c +++ b/src/main/c/Hangman/word_selector.c @@ -1,33 +1,67 @@ #include "word_selector.h" +#include "playHangman.h" -const char wordsList[NUM_WORDS][MAX_WORD_LENGTH + 1] = { - "skill", +// easy words +const char wordsList_easy[NUM_WORDS][MAX_WORD_LENGTH + 1] = { + "apple", "world", - "difference", - "celebration", - "association", - "customer", + "banana", + "cat", + "lemon", + "dog", "mood", - "agreement", - "audience", - "professor", + "orange", + "kite", + "nest", "year", - "dealer", - "patience", - "table tennis", - "pollution", - "awareness", + "grape", + "sun", + "mouse", + "tennis", + "queen", "problem", "vehicle", "death", "cousin" }; -const char* selectRandomWord() { +// hard words +const char wordsList_hard[NUM_WORDS][MAX_WORD_LENGTH + 1] = { + "database", + "programming", + "mountain", + "customer", + "table tennis", + "customer", + "laughter", + "expression", + "audience", + "professor", + "twilight", + "dealer", + "symphony", + "table tennis", + "pollution", + "inspiration", + "supermarket", + "difficulty", + "budget", + "quarter" +}; + +const char* selectRandomWord(int difficulty) { - // pick a random number and assign it to index of wordsList array + // pick a random number and assign it to index of wordsList_easy array srand((unsigned int)time(NULL)); int randomIndex = rand() % NUM_WORDS; - return wordsList[randomIndex]; + switch(difficulty){ + case 1: + return wordsList_easy[randomIndex]; + case 2: + return wordsList_hard[randomIndex]; + default: + printf("Invalid difficulty level. Using easy difficulty.\n"); + return wordsList_easy[randomIndex]; + } } \ No newline at end of file diff --git a/src/main/c/main.c b/src/main/c/main.c index 4f8b2c5..6155d68 100644 --- a/src/main/c/main.c +++ b/src/main/c/main.c @@ -30,7 +30,7 @@ int main(){ switch (option){ case 1: - playHangman(selectRandomWord()); + playHangman(); break; case 2: pong();