Question
Program in C Write an interactive program that will allow a user to play the game of Hangman. You will need to: ? You will
Program in C
Write an interactive program that will allow a user to play the game of Hangman. You will need to: ? You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of the guessed letters (letters) o one for the users word guess (guess) ? Declare additional variables as needed ? At the beginning of each game: o word to be guessed array - start with an empty string. ? Read a word from the file and store it in the word to be guessed array. o word in progress array should be adjusted to the correct length (that is the same size as the word read from the file but consists only of * (asterisks) in the beginning (starword) o guessed letters array should be empty a character is added with each guess ? An integer will keep track of how many characters are in the array HOW TO PLAY THE GAME ? Allow the user to guess letters one character at a time. ? At every stage of the game, the user should be able to view the current state of the word in progress (starword) and the list of guessed letters (letters) ? If any letter is correctly guessed the player is notified and the letter appears in its proper location in the word in progress array (starword), this array is displayed again with the letter(s) in place and the user can input a word ? If a letter is not correct, the number of used guesses is increased. ? In ALL cases, the guessed letter should be added to the array of guessed letters ? The user is allowed up to 6 incorrect guesses. ? The game is over when the word is guessed correctly or the six incorrect guesses are used up. ? If the player guesses the word correctly, the player is notified that they have won and the correct word is displayed. ? If the player does not get the correct word, the player is notified that they have lost and the correct word is displayed. ? When the game is over, the user should be allowed to play again without having to execute the program again. (The player will play again with the next word in the file) Helpful Hints ? Remember that the C language is case sensitive. For this program a = = A. In order to do this, you will need to convert all input letters to upper or lowercase either before or during the letter matching process. You will need to have a preprocessor directive to include the library file ctype.h in order to access these functions. ? Be sure to add the hangmanWords.txt file to your project 2 Other Requirements ? You must have meaningful variable and function names. ? You must use consistent and proper indentation ? You must use sufficient comments that tell a programmer what is happening in the program ? You must have at least 8 user-defined functions with meaningful names that perform the specified tasks: o A function that displays the instructions/ rules on how to play the game. o A function that determines if the player would like to play again (y or n) o A function that plays one round of the game o A function that changes a character array to all upper case or all lower case letters o A function that creates the starword , an array of * the same size as the solution word o A function that gets a character from the user and adds that character to an array of all the letter that have been guessed o A function that searches the solution word and replaces any asterisks in the starword with the character o A function that gets a guess word from the user, compares it to the solution and tells the user if they won ? You must use function prototypes placed before the main function and all function definitions must follow the main function. ? All function prototypes and definitions must have a comment describing what the function does. #define _CRT_SECURE_NO_WARNINGS #include #include #include #define MAXGUESSES 6 Sample Output: WELCOME TO HANGMAN! Please read the following instructions before you play. -You will be presented with a word to be guessed -Guess letters one at a time -You can have up to six incorrect letter guesses -You can only guess the word when you have made a correct letter guess -The game will be OVER when you have guessed the word correctly Or when you have guessed letters incorrectly SIX times. HAVE FUN! Here are the letters guessed so far: ********* Guess a letter: n ------------------------------- The letter was in the word, you can now guess the word: *N******* Guess the word: answering That is not the correct word 3 Here are the letters guessed so far: N *N******* Guess a letter: w The letter was not in the word, the value of wrongGuesses is now 1 Here are the letters guessed so far: NW *N******* Guess a letter: e ------------------------------- The letter was in the word, you can now guess the word: *N**E**** Guess the word: understand That is not the correct word Here are the letters guessed so far: NWE *N**E**** Guess a letter: u ------------------------------- The letter was in the word, you can now guess the word: UN**E**** Guess the word: universal You won that round, congratuations! Would you like to play another round (y or n)? y Here are the letters guessed so far: ******** Guess a letter: r ------------------------------- The letter was in the word, you can now guess the word: *******R Guess the word: forever That is not the correct word Here are the letters guessed so far: R *******R Guess a letter: e ------------------------------- The letter was in the word, you can now guess the word: E****EER Guess the word: engineer 4 You won that round, congratuations! Would you like to play another round (y or n)? y Here are the letters guessed so far: ***** Guess a letter: o The letter was not in the word, the value of wrongGuesses is now 1 Here are the letters guessed so far: O ***** Guess a letter: p The letter was not in the word, the value of wrongGuesses is now 2 Here are the letters guessed so far: OP ***** Guess a letter: r ------------------------------- The letter was in the word, you can now guess the word: R***R Guess the word: rover That is not the correct word Here are the letters guessed so far: OPR R***R Guess a letter: i The letter was not in the word, the value of wrongGuesses is now 3 Here are the letters guessed so far: OPRI R***R Guess a letter: e The letter was not in the word, the value of wrongGuesses is now 4 Here are the letters guessed so far: OPRIE R***R Guess a letter: u The letter was not in the word, the value of wrongGuesses is now 5 Here are the letters guessed so far: OPRIEU R***R Guess a letter: x 5 The letter was not in the word, the value of wrongGuesses is now 6 You did not win this round, the solution was RADAR Would you like to play another round (y or n)? n Press any key to continue . . . Use these prototypes //this function provides instructions to the user on how to play the gamevoid HangmanRules();//this function asks the user if they want to play another game (y or n)void PlayAgain(char *againPtr);//this function runs one game.//input: character from the file, void return type//all other functions to Play one round of a game//are called from within the PlayOneGame functionvoid PlayOneGame(char solution[]);//this function changes a character array to all uppercase lettersvoid UpperCaseWord(char word[]);//this function creates the starword arrayvoid CreateStarword(char starword[], int length);//this function gets the users guess letter and adds it to the lettersGuessed array//returns the letter entered by the userchar GetTheLetterGuess(char lettersGuessed[], int *numPtr);//this function replaces any asterik in the starword with the current character enteed by the userint ReplaceStars(char solution[], char starword[], char letter);//this function gets the guess word,//compares the solution and the guess word//tells the user if they have won and returns a 1//otherwise it returns a 0int DidYouWin(char solution[]);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started