#include <iostream>
void PrintIntroduction(int Difficulty)
{
// Print game scenario to terminal
std::cout << "\n\nYou're an entrepreneur trying to source bikes to open up your own Cycle Store... \n";
std::cout << "You need to enter the correct level " << Difficulty <<" padlock code to successfully gain ownership of a new bike... \n";
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
// Declare 3 number code
const int CodeA = 2;//rand();
const int CodeB = 3;//rand();
const int CodeC = 4;//rand();
//Calculate and declare sum and product of 3 number code
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//Print sum and product to terminal
std::cout << "\n+ Modern padlocks only have 3 numbers nower days. \n";
std::cout << "+ These 3 numbers add up to: " << CodeSum << std::endl;
std::cout << "+ These 3 numbers multiply to give: " << CodeProduct << std::endl;
// Store player guess
int GuessA, GuessB, GuessC;
std::cout << "\nEnter your 3 numbers separated by a space or the enter key: \n";
std::cin >> GuessA >> GuessB >> GuessC;
//Calculate and declare sum and product of player guess
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
//Print Win/Lose to terminal
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nGood job, you're one bike closer to your empire, now leave the scene casually and quickly, there's more work to be done... \n\n";
return true;
}
else
{
std::cout << "\nUnlucky, you spent too long guessing the wrong numbers and the owner caught you... \nLost a few teeth, but don't worry, you can buy some replacements when you're rolling in that Cycle Store money. \nDon't give up now! \n\n";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxLevel = 5;
while (LevelDifficulty <= MaxLevel) // Loop the game until all levels are completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); //Clears any errors
std::cin.ignore(); //Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
//Increase level difficulty
}
}
std::cout << "\nNice work out there, you've aquired enough merchandise to call it a selection. Now to find some bike-less chumps to sell 'em to. \n";
return 0;
}
1 Like