#include <iostream> // Preprocessor Directive
using namespace std; // Uses the Standard Namespace
void PrintIntroduction(int Difficulty) {
cout << "\n\nd888888P oo dP dP dP \n";
cout << " 88 88 Y8. .8P \n";
cout << " 88 88d888b. dP 88d888b. 88 .d8888b. Y8aa8P \n";
cout << " 88 88' `88 88 88' `88 88 88ooood8 d8' `8b \n";
cout << " 88 88 88 88. .88 88 88. ... 88 88 \n";
cout << " dP dP dP 88Y888P' dP `88888P' dP dP \n";
cout << " 88 \n";
cout << " dP \n\n";
// Print welcome messages to the terminal
cout << "You are a secret agent breaking into a level " << Difficulty;
cout << " secure server room...\nEnter the correct code to continue...\n\n";
}
bool PlayGame(int Difficulty) {
PrintIntroduction(Difficulty);
// Declare 3 number code | Declaration Statements
const int CodeA = rand();
const int CodeB = rand();
const int CodeC = rand();
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// Print CodeSum and CodeProduct to the terminal
cout << "+ There are 3 numbers in the code.";
cout << "\n+ The codes add up to: " << CodeSum;
cout << "\n+ The codes multiply to give: " << CodeProduct << endl;
// Store player guess
int GuessA, GuessB, GuessC;
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) {
cout << "\n*** Well done agent! You have extrated a file! Keep going! ***";
return true;
} else {
cout << "\n*** You entered the wrong code! Careful agent! Try again! ***";
return false;
}
}
int main() { // Main Function
int LevelDifficulty = 1;
int const MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty) { // Loop game until all levels are completed
bool bLevelComplete = PlayGame(LevelDifficulty);
cin.clear(); // Clears any errors
cin.ignore(); // Discards the buffer
if (bLevelComplete) {
++LevelDifficulty;
}
}
cout << "\n*** Great work agent! You got all the files! Now get out of there! ***\n";
return 0; // Return Statement
}
1 Like
Very cool game
1 Like