Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Word guessing game: Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend

Word guessing game:

Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend the use of vectors for this assignment.

Win condition: If the user correctly guesses and reveals all of the letters, the guessing will end and print "You win" and reveal the word.

Loss condition: The user will only see a "game over" print and be revealed the word.

Required functionality:

use vector[rand() % vectorName.size()] to grab a random element from the vector. Be smart about this part.

Main()

Should contain the following variables:

two vectors chars. One array named answer to hold a word for the user to guess. the second an exact same sized char vector initialized all to the "*" character

an int named guesses initialized to double the size of your size variable.

an int named revealed initialized to zero.

a char named guess initialized to '0'.

This should contain the base functionality of the game. A loop should control the game and check if guesses are greater than zero and revealed is less than size. Don't forget to use the vector.size() function to get the vector's size.

Ask the user for a guess and call check guess.

if check guess returns true, let the user know they revealed a letter and call revealLetter().

decrement guesses by one as now a turn has been consumed. Do this outside of any conditional logic above^

perform a check to see if revealed == size to see if the user revealed all the letters.

display() - This function is called anytime the contents of the vector needs to be printed on the screen.

checkGuess() - This function will return if a match is found in the answer vector passed into it. You will need to pass the user's guess to compare, the correct answer vector. This function might not make sense to you at first, but try to use this as a utility function. If it's still confusing, try doing reveal letter first and see if this still feels necessary. This might also be a good function to check for the user guessing a letter that's already been revealed. Just a thought!

revealLetter() - This void function should be passed the matching guess char, the answer vector, the word vector, and REFERENCE to "revealed" so it can be iterated. This function should look through the answer vector and find the matching element between the user's guess and the answer vector. Copy the answer element data into the word array at that exact position to simulate revealing the letter. Lastly, increment revealed.

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago