However, I am considering whether I should make the game deeper or not.
And here is the code:
// This preprocessor directive will include the iostream header file
#include <iostream>
#include <ctime>
void PrintIntroduction(int Difficulty)
{
std::cout << "\n\nLevel: " << Difficulty;
if (Difficulty < 2)
{
std::cout << "\nYou wake up. Your head feels smashed. It looks like you're locked up in a dark room. The door is locked, but no problem.\n";
std::cout << "You're a skilled hacker who knows how to hack a door. Let's get to it." << std::endl;
std::cout << "Enter the correct code to continue... \n";
}
else if (Difficulty > 4)
{
std::cout << "\nTHERE IS LIGHT COMING FROM THE DOOR! ALMOST THERE\n";
std::cout << "Enter the correct code to continue... \n";
}
else
{
std::cout << "\nTHIS DOOR SEEMS HARD BUT YOU CAN DO IT!\n";
std::cout << "Enter the correct code to continue... \n";
}
}
bool PlayGame(int Difficulty)
{
// Prints a welcome message to the terminal
PrintIntroduction(Difficulty);
// Declaring our different constant variables
const int CodeA = rand() % Difficulty + 1;
const int CodeB = rand() % Difficulty + 1;
const int CodeC = rand() % Difficulty + 1;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// print CodeSum and CodeProduct to the terminal
std::cout << std::endl;
std::cout << "+ There are 3 numbers in the code \n";
std::cout << "+ The codes add-up to: " << CodeSum << std::endl;
std::cout << "+ The codes multiply to give: " << CodeProduct << std::endl;
// Store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// check if the players guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct) {
std::cout << "\n+ YOU GOT IT!, KEEP GOING... +\n";
return true;
} else {
std::cout << "\n+ WRONG CODE!, BUT DON'T WORRY YOU CAN DO IT... +";
return false;
}
}
int main()
{
srand(time(NULL)); // Create new random sequence based on time of day
int LevelDifficulty = 1;
const int MaxLevelDifficulty = 5;
while(LevelDifficulty <= MaxLevelDifficulty)
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // clears any error
std::cin.ignore(); // discards the buffer
if(bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "\n+ YOU GOT OUT, CONGRATZ! +";
return 0;
}