 # TripleX - Progress so far

``````#include <iostream>

void PrintIntroduction(int Difficulty)
{
// Initialize the game's story
std::cout << "\n\nYou have to escape the prison to save your daughter!\n";
std::cout << "But a security door level " << Difficulty << " lies in front of you!\n";
std::cout << "You have to enter the correct code to open it...\n";
}

bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
const int CodeA = 7, CodeB = 5, CodeC = 2;

const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;

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;
std::cout << "Your guesses add-up to: " << GuessSum << std::endl;
int GuessProduct = GuessA * GuessB * GuessC;
std::cout << "Your guesses multiply to give: " << GuessProduct << std::endl;

// Checks if the player guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "Congratulations! You opened the door!";
return true;
}
else
{
std::cout << "Wrong code! Try again. Hurry!";
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();// Will clear any errors, preventing the program to loop endlessly
std::cin.ignore();// Will discard the buffer

if (bLevelComplete)
{
LevelDifficulty++;
}

}

std::cout << "\nYou're finally out! Go save your daughter!";

return 0;
}
``````
1 Like

Awesome progress!! ``````#include <iostream>

void PrintIntroduction(int difficulty) {
std::cout << "_______________________________________________________\n\n";
std::cout << "Now you are at LEVEL " << difficulty <<" security\n\n";
std::cout << "You need to enter the correct codes to breach the security... \n\n";
std::cout << "_______________________________________________________\n\n";

}

void ASCIIArt() {
std::cout << "_______________________________________________________\n";
std::cout << "/                                                       /\n";
std::cout <<
"|            Ha ha, I hacked your system !!           |\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";
}

bool HackTheSystem(int level_Difficulty) {

PrintIntroduction(level_Difficulty);

//code to hack the computer
int CodeA = rand();
int CodeB = rand();
int CodeC = rand();

int CodeSum = CodeA + CodeB + CodeC;
int CodeProduct = CodeA * CodeB * CodeC;

//Printing the code sum and code product
std::cout << "There are 3 numbers in the code... \n";
std::cout << "The codes add-up to : " << CodeSum << std::endl;
std::cout << "The code multiply to give : " << CodeProduct << std::endl;

//player input guess
int GuessA, GuessB, GuessC;

std::cout << std::endl;
std::cout << "Enter The Code : \n";
std::cin >> GuessA >> GuessB >> GuessC;

int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;

std::cout << std::endl;

// check the hacker code and the actual code is equal
if(GuessSum == CodeSum && GuessProduct == CodeProduct) {
std::cout << "You have successfully breached into level " << level_Difficulty << " security.\n\n\n";
std::cout << "_______________________________________________________\n\n";
return true;
}
else {
std::cout << "No! code you have entered was wrong!! TRY AGAIN !! \n\n\n";
std::cout << "_______________________________________________________\n\n";
return false;
}
}

//main() called when the program starts
int main() {
std::cout << "YOU ARE A VIGILANTE HACKER WANTS TO HACK THE DARK WEBSITE... \n\n";
std::cout << "YOU NEED TO BREACH INTO 5 LEVEL OF SECURITY TO HACK THE SYSTEM.\n\n";

int levelDifficulty = 1;
const int maxLevel = 5;
while (levelDifficulty <= maxLevel)
{
bool bLevelComplete = HackTheSystem(levelDifficulty);

std::cin.clear();
std::cin.ignore();

if(bLevelComplete) {
++levelDifficulty;
}

}

ASCIIArt();
return 0;
}
``````

slight edit made to remove watched word Its Okay, sorry!! for that word…

1 Like