#include <iostream>
#include <string>
#include <ctime>
using namespace std;
void PrintIntroduction(int Difficulty)
{
cout << "\nYou have been kidnapped!\n";
cout << "You must guess the lock combination to escape the room!\n";
cout << "There are 5 rooms and each lock consists of three numbers\n";
cout << "This first room has a lock difficulty of " << Difficulty << "\n" << endl;
}
bool PlayGame(int Difficulty)
{
//-Correct Codes-
int CodeA = rand() % Difficulty + Difficulty;
int CodeB = rand() % Difficulty + Difficulty;
int CodeC = rand() % Difficulty + Difficulty;
//Code Hints
int CodeSum = CodeA + CodeB + CodeC; int CodeProduct = CodeA * CodeB * CodeC;
//Guesses
int GuessA, GuessB, GuessC;
//Misc
string EnterGuess = "\n\nEnter your guess one digit at a time:";
string Breath = "You also gained a little breathing room giving you more time to make a guess!";
bool Escaped = false;
cout << "\nYou are now in room " << Difficulty;
cout << "\nHint 1: All three numbers total up to: " << CodeSum;
cout << "\nHint 2: The code when multiplied together equals: " << CodeProduct;
//To be ran until you escape (will change later)
while(Escaped != true)
{
//Insert Guesses (one digit at a time)
cout << EnterGuess << endl;
cin >> GuessA;
cin >> GuessB;
cin >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if(GuessSum == CodeSum && GuessProduct == CodeProduct)
{
cout << "\nYou are correct, you escaped room " << Difficulty << "\n";
cout << Breath << endl;
return true;
}else
{
return false;
}
}
}
int main()
{
int LevelDifficulty = 1;
PrintIntroduction(LevelDifficulty);
srand(time(NULL));
const int MaxDifficulty = 5;
int Lives = 3;
while(LevelDifficulty <= MaxDifficulty) //Loop Game until all levels completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
cin.clear(); //Clears any Errors
cin.ignore(); //Discards the buffer
if(Lives != 1)
{
if (bLevelComplete)
{
//increase difficulty
++LevelDifficulty;
Lives++;
}else
{
Lives--;
cout << "You got it wrong, careful you only have time for " << Lives << " more guesses!\n";
}
}else
{
cout << "\n\nOH, NO!!! You have been caught trying to escape!\n";
return 0;
}
}
return 0;
}
2 Likes
I like the escape room angle!