This assignment moves us past simple single-file programs into more interesting
ID: 3878726 • Letter: T
Question
This assignment moves us past simple single-file programs into more interesting multi-file program:s We also write a game that, if not a viable League of LegendsTM competitor, is at least reasonably enjoyable at the Extreme Bonus level. Along the way, we'll utilize a Makefile, either the ddd or gdb debugger, and Umbrello to design our class and use case diagrams Full Credit Requirements Boom is a classic word or phrase guessing game with limited tries and something catastrophic if the word is missed - a firecracker goes (you guessed it) "Boom!". A game in progress looks something like the screen shot to the right. Below is a simple UML class diagram of the Full Credit version of the game. Note that Main isn't actually a class it's simply the usual main function. This time around, implement a h and cpp for each class ain + main): int izzl use - solution : string - quesses 2551: bool + Puzzle(solution : string) + guess(c: char): boo + solve(proposed solution: string): string + to_string): string + get solution(): strin - time: int + Fuse(time: int + burn(): bool + to string): strin The Puzzle class represents 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 Puzzle 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' andExplanation / Answer
my code so far
#include <iostream>
#include <string>
using namespace std;
//Robin Brust
//CS 161/Homework 5
void welcome()
{
cout<<"Welcome to Robin's guessing game."<<endl;
cout<<"The object of the game is to be the user with the"<<endl;
cout<<"least points. Player 1 will enter a word that"<<endl;
cout<<"player 2 must guess. For every incorrect guess 1 point will"<<endl;
cout<<"be added to player ones score. For every correct guess a point"<<endl;
cout<<"will be added to player twos score. If you think you know the"<<endl;
cout<<"solution you may enter it at anytime. Good luck"<<endl<<endl;
cin.get();
}
string player_one()
{
char player_one[20];
cout<<"Player 1 please enter your name"<<endl;
cin>>player_one;
cin.get();
return (player_one);
}
void game_play()
{
char word[25];//Creates memory for the word that is to be guessed
char blank[25];//creates blank spaces
char guess;
cout<<player_one()<<" please enter a word or phrase with 25 or less characters"<<endl;
int counter=0; //simple counter
int correct=0;//1=correct answer, 0=wrong answer
cin.getline (word,25);
strlen(word);
cout<<"The word is "<<strlen(word)<<" characters long!"<<endl;
int length=strlen(word); //stores the length of the word or phrase
for (counter = 0; counter < length; counter++)//converts the letters to uppercase
{
word[counter] = toupper(word[counter]);
}
strcpy(blank,word);//Copies the word to the 'blank' array
for (counter = 0; counter < length; counter++)
{
if (isalnum(word[counter])) blank[counter] = '_'; //converts characters to _'s to represent blanks
else blank[counter] = word[counter];
}
char player_two[20];
cout<<"Player 2 please enter your name"<<endl;
cin>>player_two;
cin.get();
//play game until the 'blank' puzzle becomes the 'right' answer
do {
cout<<"The current blank puzzle is: "<<blank<<"."<<endl;
cout<<player_two<<" enter a guess."<<endl;
cin>>guess;
guess = toupper(guess);
for (counter = 0; counter <= length; counter++) //check guess
{
if (guess == word[counter])
{
blank[counter] = guess; //fill in the puzzle with the letter
}
}
}
while (strcmp (word,blank) != 0);
cout<<"Winner!"<<endl;
cin.get();
}
bool play_again()
{
char again;
cout<<"Would you like to play again? y/n "<<endl;
cin>>again;
cin.get();
return (again == 'y' || again == 'Y');
}
int main()
{
welcome();
do{
game_play();
}while (play_again());
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.