Browse Source

adding difficulty to playHangman part one

remotes/origin/Saba
Saba Fazlali 11 months ago
parent
commit
50cf84877d
  1. 7
      .idea/vcs.xml
  2. 10
      src/main/c/Hangman/playHangman.c
  3. 4
      src/main/c/Hangman/playHangman.h

7
.idea/vcs.xml

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/Unity" vcs="Git" />
</component>
</project>

10
src/main/c/Hangman/playHangman.c

@ -9,14 +9,22 @@ char toLower(char ch) {
return ch; return ch;
} }
void playHangman(char *wordToGuess) {
void playHangman() {
char *wordToGuess;
int mistakes = 0; int mistakes = 0;
int score = 10; int score = 10;
char guessedLetters[30] = ""; //Guessed letters char guessedLetters[30] = ""; //Guessed letters
char currentGuess[50]; //Current state of the guessed word char currentGuess[50]; //Current state of the guessed word
int difficulty;
displayRules(); displayRules();
printf("choose the difficulty level: (1 or 2)\n");
printf("1. Easy \n");
printf("2. Hard \n");
scanf("%d", &difficulty);
wordToGuess = selectRandomWord(difficulty);
// Initialize the current guess and print the rules // Initialize the current guess and print the rules
initializeHangman(wordToGuess, currentGuess); initializeHangman(wordToGuess, currentGuess);
currentState(currentGuess, mistakes); currentState(currentGuess, mistakes);

4
src/main/c/Hangman/playHangman.h

@ -10,13 +10,13 @@
// Include function implementations directly from .c files // Include function implementations directly from .c files
void playHangman(char *wordToGuess);
void playHangman();
void initializeHangman(char *wordToGuess, char *currentGuess); void initializeHangman(char *wordToGuess, char *currentGuess);
void printRules(); void printRules();
void drawHangman(int incorrectGuesses); void drawHangman(int incorrectGuesses);
void currentState(char *currentGuess, int mistakes); void currentState(char *currentGuess, int mistakes);
const char* selectRandomWord(); const char* selectRandomWord();
const char wordsList[NUM_WORDS][MAX_WORD_LENGTH + 1];
const char wordsList_easy[NUM_WORDS][MAX_WORD_LENGTH + 1];
void displayRules(); void displayRules();
#define MAX_MISTAKES 6 #define MAX_MISTAKES 6

Loading…
Cancel
Save