Browse Source

adding difficulty to initialize (part two)

remotes/origin/Saba
Saba Fazlali 11 months ago
parent
commit
c726d4f19a
  1. 68
      src/main/c/Hangman/word_selector.c
  2. 2
      src/main/c/main.c

68
src/main/c/Hangman/word_selector.c

@ -1,33 +1,67 @@
#include "word_selector.h" #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", "world",
"difference",
"celebration",
"association",
"customer",
"banana",
"cat",
"lemon",
"dog",
"mood", "mood",
"agreement",
"audience",
"professor",
"orange",
"kite",
"nest",
"year", "year",
"dealer",
"patience",
"table tennis",
"pollution",
"awareness",
"grape",
"sun",
"mouse",
"tennis",
"queen",
"problem", "problem",
"vehicle", "vehicle",
"death", "death",
"cousin" "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)); srand((unsigned int)time(NULL));
int randomIndex = rand() % NUM_WORDS; 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];
}
} }

2
src/main/c/main.c

@ -30,7 +30,7 @@ int main(){
switch (option){ switch (option){
case 1: case 1:
playHangman(selectRandomWord());
playHangman();
break; break;
case 2: case 2:
pong(); pong();

Loading…
Cancel
Save