#include <iostream>
void LossGraphic()
{
//This is the graphic if the player loses
std::cout << " _ ._ _ , _ ._\n";
std::cout << " (_ ' ( ` )_ .__)\n";
std::cout << " ( ( ( ) `) ) _)\n";
std::cout << " (__ (_ (_ . _) _) ,__)\n";
std::cout << " `~~`\\ ' . /`~~`\n";
std::cout << " ; ;\n";
std::cout << " / \\ \n";
std::cout << "_____________/_ __ \\_____________\n";
}
void PrintIntroduction(int Difficulty)
{
//This is the text setup for the game
std::cout << "As the smoke clears you look around to see 5 bombs rigged to blow!";
std::cout << "\nThe bomb defuser turns to you and yells,\n";
std::cout << "\"We need to cut the correct wires to stop the #" << Difficulty << " bomb!\"\n";
}
bool PlayGame (int Difficulty)
{
PrintIntroduction(Difficulty);
//Declare the 3 number code
const int WireA = rand();
const int WireB = rand();
const int WireC = rand();
const int WireSum = WireA + WireB + WireC;
const int WireProduct = WireA * WireB * WireC;
/*
This is a multiline comment
boop
*/
//Print WireSum and WireProduct to terminal
std::cout << "\nThere are 3 numbered wires to cut.\n";
std::cout << "The sum of the numbers is " << WireSum << ".\n";
std::cout << "The numbers mulitplied together equal " << WireProduct << ".\n";
std::cout << "What number wire should they cut? ";
//initialise the player's guess
int PlayerGuessA, PlayerGuessB, PlayerGuessC;
//Input & display the player's guess
std::cin >> PlayerGuessA >> PlayerGuessB >> PlayerGuessC;
std::cout << "\"Cut the #" << PlayerGuessA << " " << PlayerGuessB << " " << PlayerGuessC;
std::cout << " wire!\" You yell.\n";
//Declare the sum & product
int GuessSum = PlayerGuessA + PlayerGuessB + PlayerGuessC;
int GuessProduct = PlayerGuessA * PlayerGuessB * PlayerGuessC;
//Win & lose conditions (check for correct guess)
if (GuessSum == WireSum && GuessProduct == WireProduct)
{
std::cout << "You move onto the next bomb";
return true;
}
else
{
std::cout << "The bomb defuser shakes his head, \"I don't think that's right!\"\n";
LossGraphic();
return false;
}
}
int main()
{
int LevelDifficulty = 1;
int const MaxLevels = 5;
while (LevelDifficulty <= MaxLevels) //loop game until completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); //Clear errors
std::cin.ignore(); //Clear input buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "Congratulations! You've defused the bombs :)";
return 0;
}
1 Like
Haha, those are some very hard to guess numbers. I think I’ve said this in another post but I love the explosion from the LossGraphic().
Cheers,
Trevor