#include <iostream>
void PrintMainTitle()
{
std::cout << " /### / ### ### ## \n";
std::cout << " / ############/ # ### /#### #### / \n";
std::cout << "/ ######### ### ## / ### /####/ \n";
std::cout << "# / # # ## ### / ## \n";
std::cout << " ## / ## ## ### / \n";
std::cout << " / ### ### /### ### /### ## /## ###/ \n";
std::cout << " ## ## ###/ #### / ### / ### / ## / ### ### \n";
std::cout << " ## ## ## ###/ ## / ###/ ## / ### /### \n";
std::cout << " ## ## ## ## ## ## ## ## ### / ### \n";
std::cout << " ## ## ## ## ## ## ## ######## / ### \n";
std::cout << " ## ## ## ## ## ## ## ####### / ### \n";
std::cout << " ## # / ## ## ## ## ## ## / ### \n";
std::cout << " ### / ## ## ## ## ## #### / / ### / \n";
std::cout << " ######/ ### ### / ####### ### / ######/ / ####/ \n";
std::cout << " ### ### ##/ ###### ##/ ##### / ### \n";
std::cout << " ## \n";
std::cout << " ## \n";
std::cout << " ## \n";
std::cout << " ## \n\n";
}
void PrintYouLoseGame()
{
std::cout << "======================================================================\n\n";
std::cout << "| |\n";
std::cout << "| ___ ___ _ _ ___ ___ ___ ___ |\n";
std::cout << "| | __ |___| | \\/ | |___ | | \\ / |___ |___| |\n";
std::cout << "| |___| | | | | |___ |___| \\\/ |___ | \\ |\n";
std::cout << "======================================================================\n\n";
}
void PrintIntroduction(int Difficulty)
{
std::cout <<"\n\nAre you secret agent breaking into a level " << Difficulty;
std::cout <<" secure server room..\nEnter the correct code to coninue..\n\n";
}
bool PlayGame(int Difficulty,int MaxDifficulty)
{
PrintIntroduction(Difficulty);
int CodeA = rand();
int CodeB = rand();
int CodeC = rand();
int CodeSum = CodeA + CodeB + CodeC;
int CodeProduct = CodeA * CodeB * CodeC;
//Print CodeSum and CodeProduct to the terminal
std::cout << "+ There are 3 number in the code";
std::cout << "\n+ The codes add-up to: " << CodeSum;
std::cout << "\n+ The codes multyply 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 player is correct
if(GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\n*** You win!\nLevel completed!!!Keep going ***";
return true;
}
else
{
std::cout << "\n*** You entered the wrong code! Careful agent..\nTry again!! ***";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
int const MaxDifficulty = 9;
while (LevelDifficulty <= MaxDifficulty) //Loop game until all levels completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); //Clears any errors
std::cin.ignore(); // Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "\n*** Great work agent! You got all the files! Now get out of there!! ***";
return 0;
}```
#include <iostream>
void PrintIntroduction(int Difficulty)
{
//Print intro dialogue to the terminal
std::cout << "\nYou wake up in a dank cellar and see a frail old man.\n";
std::cout << "\"You must complete our tests if you wish to escape this cursed spire.\"\n";
std::cout << "The level of difficulty for this floor is " << Difficulty << std::endl;
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
//Declaring 3 numbers
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
std::cout << "\n+ There are three numbers in each test,\n";
std::cout << " you must discover each of them before moving on to the next floor.\n";
std::cout << "+ When all three are combined, they add up to: " << CodeSum;
std::cout << "\n+ When the numbers are multiplied together they equal: " << 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\n*** \"You are correct and may move up the staircase,\n";
std::cout << "There, you will find your next challenge.\" ***\n";
return true;
}
else
{
std::cout << "\n\n*** You are incorrect you fool, try again... ***\n";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
int const MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty) // Loop 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;
}
}
std::cout << "\n*** Congratulations, youve made it out of the spire. ***";
return 0;
}
I went on a bit of a terminal ANSI color spree.
#include <iostream>
#include <string>
#include <array>
#include <chrono>
#include <random>
#if WIN32
#include <windows.h>
bool EnableAnsiEscapes() {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if(hConsole != INVALID_HANDLE_VALUE) {
DWORD currentMode = 0;
if(GetConsoleMode(hConsole, ¤tMode)) {
SetConsoleMode(hConsole, currentMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}
}
// Used to return false on error, but that breaks support for terminals like MINGW, so if the Windows version
// does not support ansi escape codes, ANSI support will not be disabled, so ANSI escapes will still be printed.
return true;
}
#else
bool EnableAnsiEscapes() { return true; }
#endif //WIN32
bool ansiSupported = true;
std::mt19937 random;
namespace Ansi {
inline std::string Reset() {
if (!ansiSupported)
return "";
return "\033[0m";
}
inline std::string Escape(const std::string& flag, const std::string& val) {
if (!ansiSupported)
return "";
return "\x1B[" + flag + val + "m";
}
std::string Clear() {
if (!ansiSupported)
return "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
// Clear whole screen and reset cursor to 0, 0
return Reset() + "\x1B[2J\x1B[0;0H";
}
std::string Bg(int val) {
return Escape("48;5;", std::to_string(val));
}
std::string Fg(int val) {
return Escape("38;5;", std::to_string(val));
}
}
long GetTime() {
auto now = std::chrono::system_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
}
void DrawCorrect() {
auto start = GetTime();
bool redraw = true;
bool invert = false;
auto last = GetTime();
while (GetTime() - start < 1500) {
if (GetTime() - last > 500) {
invert = !invert;
redraw = true;
}
if (redraw) {
std::cout << Ansi::Clear();
if (!invert)
std::cout << Ansi::Fg(2);
else
std::cout << Ansi::Fg(0) << Ansi::Bg(2);
std::cout << R"(/=======================================\)" << "\n"
<< R"(| _____ _ |)" << "\n"
<< R"(| / ____| | | |)" << "\n"
<< R"(| | | ___ _ __ _ __ ___ ___| |_ |)" << "\n"
<< R"(| | | / _ \| '__| '__/ _ \/ __| __| |)" << "\n"
<< R"(| | |___| (_) | | | | | __/ (__| |_ |)" << "\n"
<< R"(| \_____\___/|_| |_| \___|\___|\__| |)" << "\n"
<< R"(| |)" << "\n"
<< R"(\=======================================/)" << Ansi::Reset() << std::endl;
last = GetTime();
redraw = false;
}
}
}
void DrawWrong(std::array<int, 3> numbers) {
std::string correctNumbers;
for(int num : numbers) {
if(!correctNumbers.empty())
correctNumbers += ", ";
correctNumbers += std::to_string(num);
}
auto start = GetTime();
bool redraw = true;
bool invert = false;
auto last = GetTime();
while (GetTime() - start < 2500) {
if (GetTime() - last > 500) {
invert = !invert;
redraw = true;
}
if (redraw) {
std::cout << Ansi::Clear();
std::cout << "The correct numbers were: " << correctNumbers << "\n\n";
if (!invert)
std::cout << Ansi::Fg(1);
else
std::cout << Ansi::Fg(0) << Ansi::Bg(1);
std::cout << R"(/======================================\)" << "\n"
<< R"(| __ __ |)" << "\n"
<< R"(| \ \ / / |)" << "\n"
<< R"(| \ \ /\ / / __ ___ _ __ __ _ |)" << "\n"
<< R"(| \ \/ \/ / '__/ _ \| '_ \ / _` | |)" << "\n"
<< R"(| \ /\ /| | | (_) | | | | (_| | |)" << "\n"
<< R"(| \/ \/ |_| \___/|_| |_|\__, | |)" << "\n"
<< R"(| __/ | |)" << "\n"
<< R"(\======================================/)" << Ansi::Reset() << std::endl;
last = GetTime();
redraw = false;
}
}
}
bool SimulateGame(int level, int lives) {
std::cout << Ansi::Fg(3) << "You are in a bank trying to break into a " << Ansi::Fg(5) << "level " << level
<< Ansi::Fg(3) << " vault... \n"
<< Ansi::Fg(3) << "You have " << Ansi::Fg(5) << lives << Ansi::Fg(3) << " lives remaining.\n"
<< "Enter the correct code to continue..." << Ansi::Reset() << "\n\n";
// Generates a random distribution based on level and how many lives the player lost
std::uniform_int_distribution<int> distrib(level + (level - 1), level * 2 - ((3 - lives) / 3));
const std::array<int, 3> numbers{distrib(random), distrib(random), distrib(random)};
const int sum = numbers[0] + numbers[1] + numbers[2];
const int product = numbers[0] * numbers[1] * numbers[2];
std::cout << Ansi::Fg(3) << "* There are three numbers in the code\n"
<< "* The codes add-up to: " << Ansi::Fg(5) << sum << Ansi::Fg(3) << "\n"
<< "* The codes multiply to give: " << Ansi::Fg(5) << product << Ansi::Fg(3) << "\n"
<< "\nPlease enter your guess: " << Ansi::Fg(5);
std::flush(std::cout);
std::array<int, 3> guesses{};
for (int& guess : guesses) {
std::cin >> guess;
std::cin.clear(); // Clear any potential errors
}
const int guessSum = guesses[0] + guesses[1] + guesses[2];
const int guessProduct = guesses[0] * guesses[1] * guesses[2];
bool wasCorrect = false;
std::cout << "\n";
if (sum == guessSum && product == guessProduct) {
DrawCorrect();
wasCorrect = true;
} else {
DrawWrong(numbers);
}
std::cout << Ansi::Reset() << std::endl;
return wasCorrect;
}
int main() {
#if WIN32
ansiSupported = EnableAnsiEscapes();
#endif //WIN32
// Initialize randomizer
random = std::mt19937(GetTime());
constexpr int maxLevel = 10;
int level = 1;
int lives = 3;
while (level <= maxLevel) {
std::cout << Ansi::Clear();
bool correct = SimulateGame(level, lives);
std::cin.ignore(std::cin.rdbuf()->in_avail());
std::cout << Ansi::Clear();
if (correct)
level++;
else {
lives--;
}
if (lives <= 0) {
std::cout << Ansi::Fg(1) << "The police have found you, game over!";
break;
}
}
if (level > maxLevel)
std::cout << Ansi::Fg(2) << "You have successfully opened the last vault, the riches are yours!";
// Always reset the console formatting at the end, some consoles don't do it for us
// looking at you powershell
std::cout << Ansi::Reset() << std::endl;
std::cin.clear();
std::cin.ignore(std::cin.rdbuf()->in_avail());
std::cout << "\nPress enter to exit...";
std::cin.get(); // Prevent terminal from closing until player presses enter
return 0;
}
Here’s my code so far. I used a for loop for my code summing/multiplication but functionally its is the same. I also moved the message printed on completion to be inside of the PlayGame function in order for a different message to be printed to the user as they no longer need to proceed to the next level as the game has finished
#include <iostream>
// Method for finding the sum of an input array of integers
int Sum(int inputs[]) {
int n, InputSum=0;
for ( n=0 ; n<3 ; ++n )
{
InputSum += inputs[n];
}
return InputSum;
}
// Method for finding the product of an input array of integers
int Product(int inputs[]) {
int m, InputProduct=1;
for ( m=0 ; m<3 ; ++m )
{
InputProduct *= inputs[m];
}
return InputProduct;
}
// Print welcome messages to the terminal
void PlayIntroduction(int Difficulty)
{
std::cout << R"(
_______ ___ ___ _________ ________ ________ ________ _________ _______ ________
|\ ___ \ |\ \ / /|\___ ___\\ __ \|\ __ \|\ ____\\___ ___\\ ___ \ |\ ___ \
\ \ __/| \ \ \/ / ||___ \ \_\ \ \|\ \ \ \|\ \ \ \___\|___ \ \_\ \ __/|\ \ \_|\ \
\ \ \_|/__ \ \ / / \ \ \ \ \ _ _\ \ __ \ \ \ \ \ \ \ \ \_|/_\ \ \ \\ \
\ \ \_|\ \ / \/ \ \ \ \ \ \\ \\ \ \ \ \ \ \____ \ \ \ \ \ \_|\ \ \ \_\\ \
\ \_______\/ /\ \ \ \__\ \ \__\\ _\\ \__\ \__\ \_______\ \ \__\ \ \_______\ \_______\
\|_______/__/ /\ __\ \|__| \|__|\|__|\|__|\|__|\|_______| \|__| \|_______|\|_______|
|__|/ \|__|
)" << '\n';
std::cout << "You awake as a woman with no name or memory.\n";
std::cout << "The room you are in is bare and only the colour white.\n";
std::cout << "There is a door with a keypad and screen. It looks like a code must be entered to open it.\n";
std::cout << "The current difficulty is " << Difficulty;
}
bool PlayGame(int Difficulty, int MaxDifficulty)
{
PlayIntroduction(Difficulty);
// Declare 3 number code
const int CodeA = rand();
const int CodeB = rand();
const int CodeC = rand();
int CodeInputs [] = {CodeA, CodeB, CodeC};
int CodeSum = Sum(CodeInputs);
int CodeProduct = Product(CodeInputs);
// Print sum and product to the terminal
std::cout << std::endl;
std::cout << "\n\n+ There are " << (sizeof(CodeInputs)/sizeof(*CodeInputs)) << " numbers in the code";
std::cout << "\n+ The codes add up to: " << CodeSum;
std::cout << "\n+ The codes multiply to give: " << CodeProduct << std::endl;
// Store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
std::cout << "You entered: " << GuessA << GuessB << GuessC << std::endl;
int GuessInputs [] = {GuessA, GuessB, GuessC};
int GuessSum = Sum(GuessInputs);
int GuessProduct = Product(GuessInputs);
// Check if the players guess is correct
if ((GuessSum == CodeSum) && (GuessProduct == CodeProduct))
{
if (Difficulty == MaxDifficulty)
{
std::cout << "\nThe door opens and you exit the facility."; // single quotes are used only for single characters, while double quotes are used for string literals
std::cout << "You are free, still unsure of where or who you are...";
}
else
{
std::cout << "\nThe door slides open. You proceed to the next level.\n\n";
}
return true;
}
else
{
std::cout << "\nThe screen reads 'ACCESS DENIED'. You must try this level again...\n\n";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
int const MaxDifficulty = 4;
// loop game until all levels completed
while (LevelDifficulty <= MaxDifficulty) // doesn't matter to compiler but include a space between while keyword and argument parenthesis
{
bool bLevelComplete = PlayGame(LevelDifficulty, MaxDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
{
++LevelDifficulty;
}
}
return 0;
}
// TODOs
// - prevent user from inputting anything but a value (use a regex?)
// - increase immersion with more output statements
Hello,
This is my first post.
For Triple X, I used the same core mechanics as the course tutorial, the changes I made were more on how the game looked and ran through functions.
Here are some of the changes I made:
- Added a menu at the beginning of the game using functions and if statements;
- Fixed a compiler warning by using srand((unsigned int) time(NULL)) instead of srand(time(NULL));
- Added a title using ###;
- Changed the while loop from int main to a function;
- Customized the dialog.
Hope this is relevant.
Thank you for the opportunity.
Best,
// This program simulates a secret agent who needs to hack into a corporate server to bring light upon a series of unfortunate events.
// The player must decipher the code and enter the right numbers into the terminal in order to breach the security protocol and access the data.
// This game was made by Kirk Paradis following the Unreal Engine C++ Developper: Learn C++ and Make Video Games course.
#include <iostream>
#include <ctime>
using namespace std;
void PrintGameLevel(int Difficulty)
{
cout << "\nYou are on level " << Difficulty << endl;
}
void PrintTripleX()
{
cout << " ####### ###### ## ##### # ##### # # " << endl;
cout << " # # # ## # # # # # # " << endl;
cout << " # ###### ## ##### # #### # " << endl;
cout << " # # # ## # # # # # " << endl;
cout << " # # # ## # ###### ##### # #" << endl;
}
void PrintMenu()
{
cout << "\nP - Play" << endl;
cout << "Q - Quit" << endl;
cout << "C - Credits" << endl;
}
int ExitGame()
{
cout << "\nExiting game..." << endl;
return 0;
}
int GameCompleteMessage()
{
cout << "\nYou have made it to the core of the servers and start looking at the data..." << endl;
cout << "\nCould it be that... 2398rh239rh319r7g13897r1g39r8!@$#@$3hgr19378rhb319fdubn9317bd9p1....error@!#..." << endl;
cout << "You've got123804124dsxwe To..1e2sxsdcs geT..g.32e23...OUT!!!23rfd..." << endl;
return 0;
}
void PrintCredits()
{
cout << "*********************************************************************************************************************" << endl;
cout << "This game was made by Kirk Paradis following the Unreal Engine C++ Developper: Learn C++ and Make Video Games course." << endl;
cout << "*********************************************************************************************************************" << endl;
}
bool PlayGame(int Difficulty) //Runs the game & applies the codes
{
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;
int GuessA{}, GuessB{}, GuessC{};
cout << "\nAgent, we're almost out of time." << "\n\nYou must decipher the access code to the server's core before it's too late!" << endl;
cout << "\nThe code is made up of three numbers." << endl;
cout << "The sum of the numbers is " << CodeSum << endl;
cout << "The product of the numbers is " << CodeProduct << endl;
cout << "\nEnter the first number..." << endl;
cin >> GuessA;
cout << "Now on to the second..." << endl;
cin >> GuessB;
cout << "and the last...think carefully..." << endl;
cin >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
cout << "\n****************" << endl;
cout << "\n***Well done!***" << endl;
cout << "\n****************" << endl;
return true;
}
else
{
cout << "\n**********************************************************" << endl;
cout << "\n***Careful, Agent! We almost got fried here. Try again.***" << endl;
cout << "\n**********************************************************" << endl;
return false;
}
}
void GameRunOnStart()
{
srand((unsigned int) time(NULL));
int LevelDifficulty = 1;
int const MaxLevel = 5;
while (LevelDifficulty <= MaxLevel)
{
PrintGameLevel(LevelDifficulty);
bool bLevelComplete = PlayGame(LevelDifficulty);
cin.clear(); // clear the failbits
cin.ignore(); // discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
}
void UserSelection()
{
char selection{};
cin >> selection;
if (selection == 'P' || selection == 'p')
{
GameRunOnStart();
}
else if (selection == 'Q' || selection == 'q')
{
ExitGame();
}
else if (selection == 'C' || selection == 'c')
{
PrintCredits();
PrintMenu();
UserSelection();
}
else
{
cout << "Wrong selection, please try again." << endl;
}
}
int main()
{
PrintTripleX();
PrintMenu();
UserSelection();
GameCompleteMessage();
return 0; // Exits the game
}
My code so far…
#include <iostream>
void PrintIntroduction(int Difficulty)
{
std::cout << "\nYou are a brave hero at floor " << Difficulty <<" of Dark Castle, fighting your way into a princess's chamber... \n";
std::cout << "Monster block your way with black magic tricks and you need to enter correct codes to brake them \n\n";
std::cout << "HINT: You need to put 3 numbers which add-up and will multiply as a values above \n\n";
}
bool PlayGame(int Difficulty)
{
// Background story printing to the console
PrintIntroduction(Difficulty);
const int CodeA = 4;
const int CodeB = 5;
const int CodeC = 6;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// Print sum and product to the terminal
std::cout << "+ There are 3 numbers in the code \n";
std::cout << "+ The codes add-up to: " << CodeSum;
std::cout << "\n+ The codes multiply to give: " << CodeProduct;
int GuessA, GuessB, GuessC;
// Store player guess
std::cout << "\n\nChoose your codes: ";
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 << "\nYou purged the black magic and move forward!\n";
return true;
}
else
{
std::cout << "\nMonster: \"You are not prepared!\"\n";
std::cout << "Monster deceived you, but you need to keep fighting! Try again and purge the witch!\n";
return false;
}
}
int main()
{
std::cout << R"(
_______________________________________
/ \
/ _ _ _ _ _ _ \
| | |_| |_| | _ _ _ | |_| |_| | |
| \ _ / | |_| |_| | \ _ / |
| | | | | \ / | | | | |
| | |_| |______| |______| |_| | |
| | ___ | |
| | _ _ ( ) _ _ | |
| | | | |_| ( ) |_| | | | |
| | |_| | | |_| | |
| / |_______| \ |
| |______________TripleX______________| /
\_______________________________________/
)" << std::endl;
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty) //Loop 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;
}
}
std::cout << R"(
w*W*W*W*w
\"."."/
//`\\
(/. .\)
(\_-_/) THANK YOU BRAVE HERO!
.-~'='~-.
/`~`"Y"`~`\
/ /(_ * _)\ \
/ / ) ( \ \
\ \_/\\_//\_/ /
\/_) '*' (_\/
| |
| |
| |
| |
| |
| |
| |
| |
w*W*W*W*w
)";
std::cout << "\n Well done! You have saved your princess... now get your reward!";
return 0;
}
#include
#include
void PrintIntroduction(int Difficulty){
//writes strings and declares variables and shows them
std::cout << "\nYour girl is in the shower and you suspect her of cheating. You need to bypass the phonelock sequences to unlock the phone and check for evidence\n";
std::cout << "Enter the correct codes to pass level " << Difficulty << " sequence.\n";
}
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 CodeMultiply = CodeA*CodeB*CodeC;
/* Writes codes to console */
std::cout << "\n+ There are 3 numbers in the password";
std::cout << "\n+ The numbers add up to: " << CodeSum;
std::cout << "\n+ The numbers multiply to: " << CodeMultiply;
//Store player's guess
int GuessA, GuessB, GuessC;
std::cout << "\n\nNumbers: ";
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if(GuessSum==CodeSum && GuessProduct==CodeMultiply)
{
std::cout << "You solved the sequence, Continue..\n";
return true;
}
else
{
std::cout << "Try Again\n";
return false;
}
}
int main()
{
srand(time(NULL)); //Creates new random sequence based on time of day
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();
std::cin.ignore();
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "\nYou found the evidence, your girl is for the streets >.<";
return 0;
}
#include
void PrintIntroduction(int Difficulty, int MaxDifficulty)
{
// Print welcome messages to the terminal
std::cout << "\n\n___________ .__ .__ ____ ___\n\\__ ___/______|__|_____ | | ____ \\ \\/ /\n | | \\_ __ \\ \\____ \\| | _/ __ \\ \\ / \n | | | | \\/ | |_> > |_\\ ___/ / \\ \n |____| |__| |__| __/|____/\\___ >___/\\ \\\n |__| \\/ \\_/\n\n\n";
std::cout << "| You are an agent trying to stop a terrorist attack.";
std::cout << "\n| A group of hackers accessed the Pentagon";
std::cout << "\n| They installed software to secretly launch nuclear missiles towards China";
std::cout << "\n| You managed to figure out where is the file that will allow you to stop the launch.";
std::cout << "\n| To access it you will have to break its " << MaxDifficulty << "-step security system";
std::cout << "\n| Each level has increased difficulty, you are currently at level " << Difficulty;
std::cout << "\n| Enter the correct code to continue...\n\n";
}
bool bPlayGame(int Difficulty, int MaxDifficulty)
{
PrintIntroduction(Difficulty, MaxDifficulty);
// Declare 3 number code
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
std::cout << "\n+ There are 3 numbers in the code";
std::cout << "\n+ The codes add-up to: " << CodeSum;
std::cout << "\n+ 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 << "\nAccess granted, you managed to cancel the launch. Congratulations!, humanity gets to see another day" << std::endl;
std::cout << "\nAcces granted, moving forward to the next verification...";
return true;
}
else
{
//std::cout << "\nAccess denied, the missiles were launched, WW3 started, humanity is doomed" << std::endl;
std::cout << "\nAcces denied, retry...";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels completed
{
bool bLevelComplete = bPlayGame(LevelDifficulty, MaxDifficulty);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "\nVerification finished, you managed to cancel the launch. Congratulations!, humanity gets to see another day" << std::endl;
return 0;
}
My game now has a kind of “sad” ending. This Is a screenshot showing the last two leves.
I also leave you my code if you want to test it (beware of the early rand madness!)
#include <iostream>
void PrintASCIIArt()
{
std::cout << "\n .... \n";
std::cout << " ,od88888bo. \n";
std::cout << " ,d88888888888b \n";
std::cout << " ,dP\"\"' `\"Y888b ,. \n";
std::cout << " d' `\"Y88b .d8b. , \n";
std::cout << " ' `Y88[ , `Y8P' db \n";
std::cout << " `88b Ybo,`',d88) \n";
std::cout << " ]88[ `Y888888P\" \n";
std::cout << " ,888) `Y8888P' \n";
std::cout << " ,d888[ `\"\"' \n";
std::cout << " .od8888P ... \n";
std::cout << " ..od88888888bo, .d888b \n";
std::cout << " `\"\"Y888888bo. .d888888b \n";
std::cout << " . `Y88b\"Y88888P\"' `Y8b \n";
std::cout << " :. `Y88[ `\"\"\"' `88[ \n";
std::cout << " |b |88b Y8b. \n";
std::cout << " `8[ :888[ , :88) \n";
std::cout << " Yb :888) `b. d8P' \n";
std::cout << " `8b. ,d888[ `Ybo. .d88[ \n";
std::cout << " Y8b. .dWARP' `Y8888888P \n";
std::cout << " `Y88bo. .od8888P' \"YWARP' \n";
std::cout << " `\"Y8888888888P\"' `\"' \n";
std::cout << " `\"Y8888P\"\"' \n";
std::cout << " `""' \n"; // warp.tmt.1997
}
void PrintIntroduction(int Difficulty)
{
// PrintASCIIArt();
// Introduction
if (Difficulty == 1)
{
std::cout << "\nYou are an explorer, attempting to retrieve a treasure from the tomb of Chandra Gupta I. The entrance wall has an inscription:\n\n";
std::cout << "\"The treasure will be kept from those not worthy of my knowledge.\n";
std::cout << "Complete this trial and I you will be one step closer to the truth... but fail and suffer the consequences.\"\n\n";
std::cout << "You enter the tomb confident of your abilities and encounter a large room.\n\n";
}
std::cout << "There is a number carved in the floor of this room: " << Difficulty << "\n\n";
std::cout << "The farthest wall has 3 empty spaces and numbered tiles are scattered in the ground. To the right of the empty spaces there are less ominous inscriptions:\n";
}
bool PlayGame(int Difficulty, int MaxDifficulty)
{
PrintIntroduction(Difficulty);
// Declare 3 number code
const int CodeA = rand();
const int CodeB = rand();
const int CodeC = rand();
// Compute and declare sum and products
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// Show messages with hints about the numbers
std::cout << ">> The sum of the numbers is " << CodeSum << ".\n";
std::cout << ">> The product of the numbers is " << CodeProduct << ".\n\n";
// Store player's guesses
int GuessA, GuessB, GuessC;
std::cout << "Insert the 3 tiles: ";
std::cin >> GuessA >> GuessB >> GuessC;
// Feedback to user
std::cout << "\nIn the wall there are three tiles: " << GuessA << " " << GuessB << " " << GuessC;
// GuessSum and GuessProduct
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// Check if the player's guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\n\nThe room starts to rumble and a secret door opens on the wall. You survived this trial!\n";
if (Difficulty < MaxDifficulty)
{
std::cout << "You cross the secret door to find another room, exactly like the one you were in.\n\n";
}
return true;
}
else
{
std::cout << "\n\nThe room starts to rumble and the floor collapses as you tried to run to the exit. The king has claimed yet another victim of greed...\n\n";
return false;
}
}
// Main function
int main()
{
int LevelDifficulty = 1;
int MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty) {
bool bLevelComplete = PlayGame(LevelDifficulty, MaxDifficulty);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "You crossed the last secret door to find the tomb of King Chandra Gupta I. Above the tomb there is a message written in paper:\n\n";
std::cout << "\"Sorry mate, I got here before. If you wish to find the treasure come for me.\n\n";
std::cout << "Yours,\n";
std::cout << " The Llama.\"\n\n";
return 0;
}
PrintIntro()
PlayGame(), then the game loops and refers your current level as # of riddle
PrintWinGame() after you solve the LAST RIDDLE!
There is permadeath so watch out
If you want to test it, here it is!
#include <iostream>
int LevelDifficulty = 1;
const int MaxLevelDifficulty = 7;
void PrintIntro()
{
std::cout << R"(
%%% %%%%%%% |#|
%%%% %%%%%%%%%%% |#|####
%%%%% % %%% |#|=#####
%%%%% % @ @ %% | | ==####
%%%%%% % (_ () ) %% | | ===##
%% %%% % \_ | %% | | =##
% %%%% % u^uuu %% | | ==#
%%%% %%%%%%%%% | | V
)" << '\n';
//Print welcome message
std::cout << "I, the Grim Reaper, approach you to make a DEAL\n";
std::cout << "If you guess the numbers in my head, i might let you FREE\n";
std::cout << "One misstep and the only one left will be ME!\n\n";
std::cout << R"(
___
/ \\
/\\ | \\
////\\| ||
//// \\ ___//\
/// \\ \
/// |\\ |
// | \\ \ \
/ | \\ \ \
| \\ / /
| \/ /
| \\/|
| \\|
| \\
| |
|_________\
)" << '\n';
}
bool PlayGame(int Difficulty)
{
if(Difficulty > 1)
{
std::cout << R"(
%%% %%%%%%% |#|
%%%% %%%%%%%%%%% |#|####
%%%%% % %%% |#|=#####
%%%%% % @ @ %% | | ==####
%%%%%% % (_ () ) %% | | ===##
%% %%% % \_ | %% | | =##
% %%%% % u^uuu %% | | ==#
%%%% %%%%%%%%% | | V
)" << '\n';
//Print welcome message
std::cout << "I see your value now, but you will need more to PROVE\n";
std::cout << "This my " << Difficulty;
switch (Difficulty)
{
case 2:
std::cout << "nd riddle\n";
break;
case 3:
std::cout << "rd riddle\n";
break;
case MaxLevelDifficulty:
std::cout << "th and LAST riddle\n";
break;
default:
std::cout << "th riddle\n";
break;
}
std::cout << "Listen well and you might not LOSE\n";
}
//Declare 3 number code
const int CodeA = 7;
const int CodeB = 4;
const int CodeC = 2;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//Print CodeSum and CodeProduct
std::cout << "\nHere is a HINT for you..." << std::endl;
std::cout << "The three numbers in my head add up to: " << CodeSum << std::endl;
std::cout << "They also multiply to give: " << CodeProduct << std::endl;
int PlayerGuessA, PlayerGuessB, PlayerGuessC;
std::cout << "Now, tell me your guess... ";
std::cin >> PlayerGuessA >> PlayerGuessB >> PlayerGuessC;
int GuessSum = PlayerGuessA + PlayerGuessB + PlayerGuessC;
int GuessProduct = PlayerGuessA * PlayerGuessB * PlayerGuessC;
std::cout << "\n\nYour guess " << PlayerGuessA << PlayerGuessB << PlayerGuessC << " ";
if(GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "is correct.\n";
std::cout << "I see, you are quite an interesting fellow.\n\n";
return true;
}
else
{
std::cout << "is incorrect.\n";
std::cout << "Sadly, your soul now belongs to me.\n";
return false;
}
}
void PrintWinGame()
{
//Print exit message
std::cout << "Very well, you have PROVEN yourself\n";
std::cout << "We are EVEN as there is no more challenges for you\n";
std::cout << "But i shall return next year, until THEN\n\n";
std::cout << R"(
___
/ \\
/\\ | \\
////\\| ||
//// \\ ___//\
/// \\ \
/// |\\ |
// | \\ \ \
/ | \\ \ \
| \\ / /
| \/ /
| \\/|
| \\|
| \\
| |
|_________\
/) /)
_ _______(/ (/_ _
(_/_(_)(_)(_(_/_) (_/__(/_
.-/ .-/
(_/ (_/
)" << '\n';
}
int main()
{
PrintIntro();
while(LevelDifficulty <= MaxLevelDifficulty)
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); //Clears any errors
std::cin.ignore(); //Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
else
{
exit(0);
}
}
PrintWinGame();
return 0;
}
Blockquote
#include
void PrintIntroduction(int Difficulty)
{
std::cout << "\n\nYou are a secret agent breaking into a level" << Difficulty;
std::cout << "server room...\nEnter the code to continue...\n\n";
}
bool bPlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
//Declare 3# code
const int NumOne = 4;
const int NumTwo = 2;
const int NumThree = 3;
const int CodeSum = NumOne + NumTwo + NumThree;
const int CodeProduct= NumOne * NumTwo* NumThree;
//Print product and sum of codes.
std::cout <<"You are finding a three digit code";
std::cout <<"\nThe Sum of your codes digits is equal to:"<< CodeSum;
std::cout <<"\nThe product of your codes digits is equal to:" << CodeProduct;
//Do while statment giving player three attempts.
int GuessA, GuessB, GuessC;
std::cin >>GuessA >> GuessB >> GuessC;
std::cout<< "You entered\n"<< GuessA << GuessB << GuessC;
const int GuessSum = GuessA + GuessB + GuessC;
const int GuessProduct= GuessA * GuessB* GuessC;
if(GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout <<"\n Congragulations you have exstracted one set of files on to the next.";
return true;
}
else
{
std::cout << "\n I'm sorry thats not right.";
return false;
}
}
int main()
{
const int MaxDifficulty = 5;
int LevelDifficulty = 1;
while (LevelDifficulty <= MaxDifficulty)
{
bPlaygame is unidentified idk why though.
bool bLevelComplete = bPlaygame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
{
//This is also unidentified i'm lost
++LevelDificulty;
}
}
std::cout << “That’s all the Files agent now get out.”;
return 0
}
Here it is so far!
#include
void PrintIntroduction(int Difficulty)
{
// The code below will write tot he terminal to start the game
std::cout << "\n\nYou step into a strange, cube-shaped room.";
std::cout << "\nYou see a keypad on the wall with ten digits and a digital screen above it reads: Level " << Difficulty;
std::cout << "\nSuddenly a voice echoes in the room, \"Enter in the correct code to move forward\"\n\n";
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
const int CodeA = 4;
const int CodeB = 6;
const int CodeC = 8;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
std::cout << "+ There are three numbers in the code" << std::endl;
std::cout << "\n+ The code adds up to: " << CodeSum << std::endl;
std::cout << "\n+ The code multiplies 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 player guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout<<"\nAn electronic chime sounds and a secret door slides open to a new cube!";
return true;
}
else
{
std::cout << "\nSuddenly a green gas seeps into the cube and you slowly fall unconcious.";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxLevel = 10;
while (LevelDifficulty <= MaxLevel)// Loop 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;
}
}
std::cout << "A secret door slides open spilling sunlight into the cube.\n";
std::cout << "You feel fresh air hit your face.\n";
std::cout << "A voice echoes in the cube, \"You are free.\n";
return 0;
}
#include <iostream>
void PrintIntroduction(int Difficulty)
{
//Print welcome messages to terminal
std::cout << "Welcome to the Dungeon of Exploding Treasure Chests.\n";
std::cout << " _ \n" <<
" | | \n";
std::cout << " __| |_ _ _ __ __ _ ___ ___ _ __ \n"
<<" / _` | | | | '_ > / _` |/ _ >/ _ >| '_ > \n";
std::cout << "| (_| | |_| | | | | (_| | __/ (_) | | | |\n"
<< " <__,_|<__,_|_| |_|<__, |<___|<___/|_| |_|\n";
std::cout << " __/ | \n"
<< " |_____/ \n";
std::cout << "You must enter the correct numbers of this 3 digit lock to get into this treasure chest.\n"
<< "You are currently in room number....." << Difficulty << std::endl;
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
const int CodeA = 4;
const int CodeB = 5;
const int CodeC = 6;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// Print CodeSum and CodeProduct to terminal
std::cout << "\n+ There are 3 codes to unlock the chest";
std::cout << "\n+ The codes add-up to: " << CodeSum;
std::cout << "\n+ The codes multiply to give: " << CodeProduct << std::endl;
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if (CodeSum == GuessSum && CodeProduct == GuessProduct)
{
std::cout << "KE-CHA! You unlocked the treasure chest!\n"
<< " <>_________________________________\n"
<< "[########[]_________________________________>\n"
<< " <>\n"
<< "And received EXCALIBUR! Well done you may proceed to the next room.\n";
return true;
}
else
{
std::cout << " DOKA!\n"
<< " _L_\n"
<< " ,\" \".\n"
<< "(> / O O > /) \n"
<< " <| _ |/\n"
<< " < (_) /\n"
<< " _/.___,>_\n"
<< " (_/ >_)\n"
<< "The treasure chest exploded!!!!!! Please try again!";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxLevel = 5;
while (LevelDifficulty <= MaxLevel)//Loop game until all levels are completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); //Clear any errors
std::cin.ignore(); //Discard the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
std::cout << "\nCongraulations You have collected all 5 Excaliburs!\n";
}
return 0;
}
I’m pretty happy with the current state
#include <iostream>
void PrintGameIntroduction ()
{
// Prints the game intro message to terminal
std::cout << "\n ___ \n- ---___- ,, /\\ , |\\ \n (' || || || ' || \\\\ _ \n (( || ||/\\\\ _-_ =||= \\\\ ,._-_ _-_, =||= / \\\\ < \\, '\\\\/\\\\ \n (( || || || || \\\\ || || || ||_. || || || /-|| || ;' \n (( // || || ||/ || || || ~ || || || || (( || ||/ \n -____- \\\\ |/ \\\\,/ \\\\, \\\\ \\\\, ,-_- \\\\, \\\\/ \\/\\\\ |/ \n _/ ( \n -_- \n";
std::cout << "\nThe entire royal family and their staff are dead or dying from strange poisons.\n";
std::cout << "As the apprentice to the now-deceased royal physician, you must brew an elixir able to save the royal family.\n";
std::cout << "Unfortunately, it's your first day as an apprentice and your masters' notes can only guide you so far.\n";
std::cout << "Can you figure out the correct volume of the ingredients in time to save the royal patients... and yourself.\n\n";
}
void PrintLevelIntroduction (int Level)
{
// Prints the level intro message to terminal
std::cout << "You step inside your ";
// Prints the level corresponding ordinal number
switch (Level)
{
case 1 :
std::cout << "1st ";
break;
case 2 :
std::cout << "2nd ";
break;
case 3 :
std::cout << "3rd ";
break;
default :
std::cout << Level << "th ";
}
std::cout << "patient's bed-chamber and take note of their symptoms.\nQuickly flipping through your masters' notes, you find the instructions for an elixir that seems fitting.\n\n";
}
bool PlayGame (int Level)
{
PrintLevelIntroduction (Level);
// Declare 3 numbers
const int IngredientA = rand();
const int IngredientB = rand();
const int IngredientC = rand();
const int IngredientSum = IngredientA + IngredientB + IngredientC;
const int IngredientProduct = IngredientA * IngredientB * IngredientC;
// Prints the sum and product
std::cout << "The elixir consists of 3 ingredients:\n";
std::cout << " > The 3 ingredients add-up to: " << IngredientSum << " mL\n";
std::cout << " > The 3 ingredients multiply to give: " << IngredientProduct << "\n\n";
// Declares variables for player input
int GuessA, GuessB, GuessC;
std::cout << "You choose: ";
// Recieves and stores player input
std::cin >> GuessA >> GuessB >> GuessC;
// Declares and initializes the sum and product of the player guesses
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// Check if player guess is correct
if (GuessSum == IngredientSum && GuessProduct == IngredientProduct)
{
std::cout << "\nYour patient slowly recover and you get to keep your head!\n\nFor now...\n\n";
// Returns PlayGame function value of success
return true;
}
else
{
std::cout << "\nYou watch with relief as the color begins to return to your patients' cheeks.\nStrange how red the skin suddenly seems... A final agonizing scream later, your patient has passed and you're dragged to the chopping block.\n\n";
std::cout << " \n |\\ |\\ \n \\\\ ' \\\\ \n'\\\\/\\\\ /'\\\\ \\\\ \\\\ / \\\\ \\\\ _-_ / \\\\ \n || ;' || || || || || || || || \\\\ || || \n ||/ || || || || || || || ||/ || || \n |/ \\\\,/ \\\\/\\\\ \\\\/ \\\\ \\\\,/ \\\\/ \n( \n -_- \n";
// Returns PlayGame function value of failure
return false;
}
}
int main ()
{
// Declares and initializes variable for level
int Level = 1;
// Calls the PrintGameIntroduction function to print the game intro message to terminal
PrintGameIntroduction();
// Declares and initializes the variable storing our max number of levels
const int MaxLevel = 10;
while (Level <= MaxLevel) // Loop game until all levels are completed
{
bool bTryAgain = false;
bool bLevelComplete = PlayGame(Level);
if (bLevelComplete)
{
// Goes to next level
++Level;
}
else
{
// Prints instructions on how to continue the game
std::cout << "\nTo try again enter any number\n\n";
// Recieves and stores player input
std::cin >> bTryAgain;
std::cout << "\n\n";
if (bTryAgain != 1)
{
// Ends the program
return 0;
}
else
{
// Calls the PrintGameIntroduction function to print the game intro message to terminal
PrintGameIntroduction();
}
}
std::cin.clear(); //Clears input errors
std::cin.ignore(); //Discards the buffer
}
std::cout << "\nWell done for your first day! Your patients all recover, and you're well-rewarded for your incredible endeavor!\n\n";
return 0;
}
#include <iostream>
void PrintIntroduction(int Difficulty)
{
std::cout << " __,_, \n";
std::cout << " [_|_/ \n";
std::cout << " // \n";
std::cout << " _// __ \n";
std::cout << " _____ ___ ___ ___ _ ___ __ __ (_|) |@@| \n";
std::cout << "|_ _| _ \\_ _| _ \\ | | __| \\ \\/ / \\ \\__ \\--/ __ \n";
std::cout << " | | | /| || _/ |__| _| > < \\o__|----| | __ \n";
std::cout << " |_| |_|_\\___|_| |____|___| /_/\\_\\ \\ }{ /\\ )_ / _\\ \n";
std::cout << " /\\__/\\ \\__O (__ \n";
std::cout << " (--/\\--) \\__/ \n";
std::cout << " _)( )(_ \n";
std::cout << " `---''---` \n";
// Print welcome messages to the terminal
std::cout << "\n-----------------------------------------------------------------------------------------------------";
std::cout << "\n You need to crack the code to turn off the dangerous artificial intelligence. ";
std::cout << "\n You are in the level " << Difficulty << " and you need to complete all of them to survive...";
std::cout << "\n-----------------------------------------------------------------------------------------------------";
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
// Declare 3 numbers code
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
std::cout << "\n- There are 3 numbers in the code";
std::cout << "\n- The codes add-up to: "<< CodeSum;
std::cout << "\n- The product of the code is: "<< CodeProduct << "\n";
// Store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
// Initializing guess sume and guess product
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// Verify if the answer is true
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nYou complete the level! Keep it up.\n";
return true;
}
else
{
std::cout << "\nThe artificial intelligent defeat you... Retry the level again\n";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxLevel = 5;
while (LevelDifficulty <= MaxLevel) // Loop game until all levels completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer
// Increasing the difficulty
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "Congratulations you defeated AI and save your life!";
return 0;
}