Starting from:

$24.99

A Typical Game Solution

The aim of this lab is to get more experience with pointers and dynamic memory.

 
 

TASKS:

 

Your task this week is to create a game in which a player guesses letters to try to replicate a hidden word. When your program starts, prompt for an input file. The input file should be a text file that contains several words and where the first line in the file indicates the total number of words in the file. Sample input file can be as follows:

 

5

available

international

season

expression

location
 

Use dynamic memory allocation to create a two-dimensional array to keep all the words read from the file. You can assume that no word is longer than 20 characters long. Then randomly choose a word to become the hidden word.

 

Initially, display the hidden word using asterisks to replace each letter. Allow the user to guess letters to replace the asterisks in the hidden word until the user completes the entire word. If the user guesses a letter not in the hidden word, display an appropriate message. If the user guesses a letter that appears multiple times in the hidden word, make sure each correct instance is replaced. When the user completes the word, display a count of the number of guesses that were required. Allow the user to continue to play as many games as wanted and allow the user to quit playing a game at any time. Use pointer notation to scan through the hidden word while the game is played.

 

A typical game played can be as shown below:

 

Enter filename: hiddenWords.txt

 

Guess a letter in the secret word:        ******

Guess a letter (* to quit) o

Guess a letter in the secret word:        ****o*

Guess a letter (* to quit) p

            Sorry, p is not in the word

Guess a letter in the secret word:        ****o*

Guess a letter (* to quit) s

Guess a letter in the secret word:        s**so*

Guess a letter (* to quit) a

Guess a letter in the secret word:        s*aso*

Guess a letter (* to quit) n

Guess a letter in the secret word:        s*ason

Guess a letter (* to quit) e

Guess a letter in the secret word:        season

Good Job!!!

You have guessed the word season in 6 tries.

Would you like to play the game again? (Y/N) : _
 

 

 


More products