Used a switch that randomized comments to the next level.
#include <iostream>
#include <cstdlib>
#include <ctime>
void PrintIntroduction(int Difficulty)
{
if (Difficulty == 1)
{
std::cout << "You are a secret agent breaking into a level " << Difficulty << " secure server room...\n";
std::cout << "Enter the correct code to continue.\n";
} else {
std::cout << "You are now breaking into a level " << Difficulty << " secure server room...\n";
std::cout << "Enter the correct code to continue.\n";
}
}
void NextLevelString()
{
int max = 5;
int x = rand()%max;
switch(x)
{
case 1:
std::cout << "You've got it!\nPlease hurry!\n\n";
break;
case 2:
std::cout << "Bro... You're a natural\nKeep going!\n\n";
break;
case 3:
std::cout << "Damm, son... Hack your way in!\n\n";
break;
case 4:
std::cout << "This is very impressive!\nRock it out!\n\n";
break;
case 5:
std::cout << "Ah, man... Wrap it up. Let's go!\n\n";
break;
default:
std::cout << "This is our chance...\nDon't blow it!\n\n";
break;
}
}
void WinString()
{
std::cout << "***************************************\n";
std::cout << "* *\n";
std::cout << "* YOU WON! *\n";
std::cout << "* *\n";
std::cout << "***************************************\n";
std::cout << std::endl;
}
void LoseString()
{
std::cout << "***************************************\n";
std::cout << "* *\n";
std::cout << "* SHAME! *\n";
std::cout << "* Very dissapointing... Pls uninstall *\n";
std::cout << "* *\n";
std::cout << "***************************************\n";
std::cout << std::endl;
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
const int CodeA = rand()%Difficulty+Difficulty;
const int CodeB = rand()%Difficulty+Difficulty;
const int CodeC = rand()%Difficulty+Difficulty;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
std::cout << std::endl;
std::cout << "There are 3 numbers in the code.\n";
std::cout << "The Sum of those numbers is: " << CodeSum << std::endl;
std::cout << "The Product of those numbers is: " << CodeProduct << std::endl;
int PlayerGuess;
int GuessA;
int GuessB;
int GuessC;
std::cout << std::endl;
std::cout << "Please enter your numbers, separated by a space\n";
std::cout << "e.g.\n";
std::cout << "1 2 3\n";
std::cout << std::endl;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
std::cout << std::endl;
if ((CodeSum == GuessSum) && (CodeProduct == GuessProduct) && (Difficulty == 10))
{
WinString();
return true;
}
if ((CodeSum == GuessSum) && (CodeProduct == GuessProduct) && (Difficulty != 10))
{
NextLevelString();
return true;
} else {
LoseString();
return false;
}
}
int main()
{
srand(time(NULL));
int Difficulty = 1;
int MaxDifficulty = 10;
while ((Difficulty <= MaxDifficulty) && (true))
{
bool GameBoolean = PlayGame(Difficulty);
std::cin.clear();
std::cin.ignore();
if (GameBoolean == true)
{
++Difficulty;
}
}
return 0;
}