Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Program in C. The program name is Hangman Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive

Write a Program in C. The program name is Hangman

Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman.

You will need to 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)

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.

Function Proto-type:

//this function provides instructions to the user on how to play the game

void 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 function

void PlayOneGame(char solution[]);

//this function changes a character array to all uppercase letters

void UpperCaseWord(char word[]);

//this function creates the starword array

void 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 user

char GetTheLetterGuess(char lettersGuessed[], int *numPtr);

//this function replaces any asterik in the starword with the current character enteed by the user

int 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 0

int DidYouWin(char solution[]);

The file name below.

word.txt:

universal

engineer

radar

Trouble

apple

KEYS

extra

kind

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

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

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

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...........

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions