Completed the Triple X Game

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 :grinning_face_with_smiling_eyes:

1 Like

mine is completed too
#include<bits/stdc++.h>

#include

#include

using namespace std;

void PrintIntroduction(string filename){

 string line="";

 ifstream inFile;

 inFile.open("triplex_art.txt");

 if(inFile.is_open()){

     while(getline(inFile,line)){

         cout<<line<<endl;

     }

    

 }

  else{

         cout<<"file failed to load";

     }

     inFile.close();

}

void PlayGame(){

int level = 2,diff=10;

while (level!=10){

const int a=rand()%diff,b=rand()%diff,c=rand()%diff;

 int Codeproduct,Codesum;

 Codeproduct=a*b*c;Codesum=a+b+c;

 int Guessproduct,Guesssum;int guess1,guess2,guess3;



cout<<"you are  a hacker required to hack into the company's server"<<endl;

cout<<"enter the code to hack"<<endl;

cout<<"ther are 3 numbers in the code"<<endl;

cout<<"the sum of the numbers is "<<a+b+c<<endl;

cout<<"the multi of the numbers is "<<a*b*c<<endl;

 cin>>guess1>>guess2>>guess3;

 Guessproduct=guess1*guess2*guess3;Guesssum=guess1+guess2+guess3;

if(Codesum==Guesssum&&Codeproduct==Guessproduct){

cout<<"you win"<<endl;

level++;

}

else{

cout<<"you loose";

return ;

}

diff=+5;

}

}

int main(){

srand(time(NULL));

string file_name= "triplex_art.txt";

PrintIntroduction(file_name);

 PlayGame();

return 0;

}
my version of the code :))

1 Like

Cool!, keep it up, I’m currently at the Bull & Cow Section :smiley:

1 Like

same here

1 Like

Very cool. I like the art. :slight_smile:

Privacy & Terms