Reference no: EM132212162
Write a program, for W_bubble class presents the game. The _solution field is the string that is the word or phrase the player is trying to guess. The _guesses array (like a vector, but without methods) holds a Boolean for each ASCII character.
For example guesses[‘a'] is true if ‘a' has been guessed, false if not. The W_bubble constructor accepts the solution, which should be stored in _solution. The guess method accepts a single character (the player's guess), and returns true if the character is valid (between ‘a' and ‘z', and not yet guessed) and false otherwise. It should also update _guesses.
The solve method accepts a proposed solution, and returns true if correct (it matches _solution) or false if incorrect. The to_string method returns the player's view of the W_bubble - that is, characters that have been guessed are visible, those that have not been guessed are replaced with a ‘_', and spaces are not changed. The get_solution getter method simply returns _solution.
The Fuse constructor accepts the time (i.e., number of guesses) that may elapse before the firecracker goes boom. The burn method decrements the remaining time, and returns true if any time remains or false if time as expired. The to_string method returns an ASCII art representation of the firecracker, with the number of segments of fuse representing the time (aka number of guesses) remaining.
Main will implement the following algorithm:
(1) Create the variables.
(2) Display a welcome message, like this:
************************
Word Bubble
************************
Enter lower case letters to guess,
! to propose a solution,
0 to exit.
(3) Begin the main loop:
(3a) Display the firecracker and the player's view of the puzzle, with a prompt, something like this:
(3b) Accept a character from the player. If it's a 0, immediately exit. If it's an exclamation point (!), ask for a proposed solution: If correct, they win, if not, they lose. If the character is an invalid guess, print "Invalid character - try again". Otherwise, update the state of the puzzle using the player's guess, including decrementing the length of the fuse.
(4) After a proposed solution, or if the firecracker explodes, display something like this if the player
won:
*** YOU WON ***
and something like this if the player lost:
*** Word Bubble ****
The answer was: Bob the builder