I am trying to learn. If you could label each part, i\'d appreciate it very much
ID: 3884595 • Letter: I
Question
I am trying to learn. If you could label each part, i'd appreciate it very much.
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
main.cpp
#include <iostream>
#include <string>
#include "fuse.h"
#include "puzzle.h"
using namespace std;
int main() {
bool keep_playing = true;
bool win = false;
int time;
string solution;
string proposed_solution;
char c;
char solved = '!';
char quit_game = '0';
cout << "Please enter a word or phrase to guess: ";
getline(cin, solution);
cout << endl;
cout << "How many guesses will the player have?: ";
cin >> time;
Puzzle my_puzzle(solution);
Fuse my_fuse(time);
/* clear the screen */
cout << string(50, ' ');
cout << "========================" << endl;
cout << " BOOM!" << endl;
cout << "========================" << endl;
cout << "Enter a lower case letter to guess: " << endl;
cout << "Enter ! to guess the whole word/phrase." << endl;
cout << "Enter 0 to quit." << endl;
while (keep_playing == true) {
cout << my_fuse.to_string() << endl;
cout << my_puzzle.to_string() << endl;
cout << "Enter a letter that you would like to guess: ";
cin.ignore();
cin >> c;
if (c == solved) {
cout << "Oh you think you got it? " << endl;
cout << "Well what is it?: ";
cin.ignore();
getline(cin, proposed_solution);
if (my_puzzle.solve(proposed_solution) == true) {
cout << "Wow, you actually got it. You win!" <<endl;
keep_playing = false;
win = true;}
else {
cout << "Not quite.. Try again." << endl;}
}
else if (c == quit_game) {
keep_playing = false; }
else {
if (my_puzzle.guess(c) == true) {
cout << "Nice job." << endl;}
else {
if (!my_fuse.burn()) {
keep_playing = false;}
}
}
if (my_puzzle.to_string() == solution) {
win = true;
keep_playing = false;}
}
if(win) {
cout << "****** YOU WIN! ******" << endl;
cout << my_puzzle.get_solution() << " was the right answer!" << endl; }
else {
cout << "BBBBBBBOOOOOOOOOOOOOOOOOOOOOMMMM!!!!!!!!!!!!!!" << endl;
cout << endl;
cout << "The correct answer was: " << my_puzzle.get_solution() << endl;
}
return 0;
}
fuse.cpp
#include "fuse.h"
bool Fuse::burn() {
if (_time > 0) {
--_time;
return true;}
else {return false;}
}
string Fuse::to_string() {
string fuse_str;
fuse_str +=",____________________, ";
fuse_str +="| | ";
fuse_str +=" ";
for(int i=0; i < _time; ++i) {
fuse_str += "~";
}
fuse_str += "* ";
fuse_str +="| | ";
fuse_str +=",____________________, ";
return (fuse_str);}
fuse.h
#ifndef FUSE_H
#define FUSE_H
#include <string>
#include <stdlib.h>
using namespace std;
class Fuse {
private:
int _time;
public:
/*Constructor for the fuse, initializing time */
Fuse(int time) : _time{time} { }
/*Decrements the fuse and returns time_left true/false*/
bool burn();
/* ASCII representation of the firecracker */
string to_string();
};
#endif
puzzle.h
#ifndef PUZZLE_H
#define PUZZLE_H
#include <string>
using namespace std;
class Puzzle {
private:
string _solution;
bool _guesses[255] = {false};
string display;
public:
Puzzle(string solution);
bool guess(char c);
bool solve(string proposed_solution);
string to_string();
string get_solution();
};
#endif
puzzle.cpp
#include "puzzle.h"
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
Puzzle::Puzzle(string solution) {
char answer;
_solution = solution;
while (1) {
cout << "Is this correct?: " << _solution << " [y/n]: ";
cin.ignore();
cin >> answer;
if (answer == 'y') {
break; }
else if (answer == 'n') {
cout << "Try again." << endl;}
else {
cout << "Invalid Input. Try again." << endl;}
}
display = solution;
display[solution.length()];
for(int i =0; i < solution.length(); ++i) {
if (solution[i] != ' ') {
display[i] = '_';}
else {
display[i] = ' ';}
}
}
bool Puzzle::guess(char c) {
int to_val = c;
if ((to_val >= 97) && (to_val <= 122) ) {
_guesses[to_val] = true;
for (int i=0; i < _solution.length(); ++i) {
if (c == _solution[i]) {
display[i] = c; }
}
return false;}
else {
cout << "Invalid Input. Please insert a character from the alphabet." << endl;
return true;}
}
bool Puzzle::solve(string proposed_solution) {
if (proposed_solution == _solution) {
return true; }
else {
cout << "Not quite.. Try again." << endl;
return false;}
}
string Puzzle::to_string() {
return display;}
string Puzzle::get_solution() {
return _solution;}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.