I have just completed the Triple X Game with some C++ knowledge.
Basically, I’ve added some ASCII art to the game & change the game to “If you get the code wrong, you die, try again from the start”.
#include <iostream>
#include <ctime>
void PrintIntroduction(int LevelDifficulty) {
// Print welcome messages of the game
std::cout << "*******************************************************************************\n";
std::cout << "You're at the " << LevelDifficulty << " level large chamber's door...\n";
std::cout << "You need to enter the correct codes or else the trap will be activated!!!\n";
}
bool PlayGame(int LevelDifficulty)
{
PrintIntroduction(LevelDifficulty);
const int CodeA = rand() % LevelDifficulty + LevelDifficulty;
const int CodeB = rand() % LevelDifficulty + LevelDifficulty;
const int CodeC = rand() % LevelDifficulty + LevelDifficulty;
int CodeSum = CodeA + CodeB + CodeC;
int CodeProduct = CodeA * CodeB * CodeC;
// Print CodeSum & CodeProduct
std::cout << "--- 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::cout << 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 the guess of the player
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\n***Congratulation!!! The doors are open!!! Going down to the next Level!!!***\n";
return true;
}
else
{
std::cout << "\n***You guess wrong!!! The trap has activated!!! Dead is inevitable...***\n";
return false;
}
}
int main()
{
srand(time(NULL)); // Create new random sequence based on time of day
// Print a treasure chest
std::cout << R"(
____...------------...____
_.-"` /o/__ ____ __ __ __ \o\_`"-._
.' / / \ \ '.
|=====/o/======================\o\=====|
|____/_/________..____..________\_\____|
/ _/ \_ <_o#\__/#o_> _/ \_ \
\_________\####/_________/
|===\!/========================\!/===|
| |=| .---. |=| |
|===|o|=========/ \========|o|===|
| | | \() ()/ | | |
|===|o|======{'-.) A (.-'}=====|o|===|
| __/ \__ '-.\uuu/.-' __/ \__ |
|==== .'.'^'.'.====|
| _\o/ __ {.' __ '.} _ _\o/ _|
`""""-""""""""""""""""""""""""""-""""`)";
std::cout << std::endl;
int LevelDifficulty = 1;
const int MaxLevelDifficulty = 5;
bool bPlayerAlive = true;
while (LevelDifficulty <= MaxLevelDifficulty && bPlayerAlive) // Loop game until all level is completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
{
// Increase the level difficulty
++LevelDifficulty;
}
else
{
bPlayerAlive = false;
}
}
// Return success & exit
if (bPlayerAlive)
{
std::cout << "***Congratulation!!! You get all the treasure in the Dungeons!!!\n";
std::cout << R"(
. ' ,
_________
_ /_|_____|_\ _
'. \ / .'
'.\ /.'
'.')";
}
else
{
std::cout << "***You die!!! Do better next time!!!***";
}
return 0;
}
Here is the image when I win:
And here is when I entered the wrong code, I’ve died but will return from the start will a little improved math skill with me