How is your Triple X game looking?

#include <iostream>

void OpeningScreen()
{
            /* Welcome Messages */
    std::cout << " _______________" << std::endl;
    std::cout << "|,----------.  |\ " << std::endl;
    std::cout << "||           |=| |" << std::endl;
    std::cout << "||          || | |" << std::endl;
    std::cout << "||       . _o| | | " << std::endl;
    std::cout << "|`-----------' |/ " << std::endl;
    std::cout << " ~~~~~~~~~~~~~~~ " << std::endl;
    std::cout << "Shadow Run TripleX Code" << std::endl;
    std::cout << std::endl;
      std::cout << "+ Apollo: 'Welcome, Runner. I am Apollo.' \n";
}

void PrintIntroduction(int Difficulty)
{
    std::cout << "+ Apollo: 'I have a job for you. I need you to crack into a level " << Difficulty << " file vault in the Matrix.'\n";
    std::cout << "+ Apollo: 'Crack the code, get the files, get paid. That easy, right? Let's hope so.' \n\n";
}

bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);

    /* Declare 3 number code */
    const int CodeA = 4;
    const int CodeB = 7;
    const int CodeC = 9;

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

    /* Print sum and product to the terminal */
    std::cout << "+ Apollo: 'So, apparently the pin to the locked files is only three numbers. Easy enough.' \n";
    std::cout << "+ Apollo: 'While I could not get the code itself, I did manage to get some hints. Apparetly the pin adds up to " << CodeSum << ".'\n";
    std::cout << "+ Apollo: 'Also apparently if you multiply them ya get " << CodeProduct << ".'\n";

    /* "cin" stores players code */
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;

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


    /* Checks if player is correct or not */
    if (GuessSum == CodeSum && CodeProduct == CodeProduct)
    {
        std::cout << "\n+ Apollo: '" << GuessA << GuessB << GuessC << " is right! We're in. I will contact you with the next update when ready.'\n\n";
        return true;
    }
    else 
    {
        std::cout << "\n+ Apollo: 'That code is wrong! The cops will be on to us if you keep that up. I'll contact you again later with another vault. '\n\n";
        return false;
    }
}

int main()
{   
    int LevelDifficulty = 1;
    const int MaxDifficulty = 10;

    OpeningScreen();

    while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels are completed
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear();
        std::cin.ignore();

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
    }
std::cout << "+ Apollo: 'That was the final code. Good work, Runner. Your payment will be wired to you by the end of the week.' ";

return 0;
}

My game so far! I even added a Opening Screen Function for my ACII art and a bit more opening text so it does not repeat the welcome and the title each time.

1 Like

Here’s my code so far:

#include <iostream>

void PrintIntroduction(int Difficulty)
{
    std::cout << "\nYou are hacking into a level " << Difficulty;
    std::cout << " bank...\nYou'll need to enter the correct codes to continue...\n\n";
}

bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);

    // Declare 3 number codes
    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 << "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 guesses
    int GuessA, GuessB, GuessC;

    std::cout << "Please enter three numbers separated by a space. Press enter when finished: ";
    std::cin >> GuessA >> GuessB >> GuessC;

    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 << "You've hacked the level " << Difficulty << " bank!!\n\n";
        return true;
    }
    else
    {
        std::cout << "Sorry, wrong code! Careful and try again.\n\n";
        return false;
    }
}

int main()
{
    int LevelDifficulty = 1;
    const int MaxDifficulty = 4;

    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 << "Congratulations you are a master bank hacker!!\n";
    std::cout << "Quick! Take the money and run! Police have been called!\n";
    return 0;
}

\n and endl are added to properly format lines in a Mac terminal. May work as intended on Linux too.

1 Like

Nice creativity!

2 Likes

This is my code so far:




Then I intend to put a condition of defeat, for example: You have erred three times you have lost.

2 Likes

I’m into it!

I like the story

:+1:

the ascii art looks screwed up because I copy/pasted from Notebook. but it comes out properly in the terminal.

The game runs, it could certainly be better. I got stuck and really frustrated with some issues at the end and now i just want to move on.

I didn’t look at all the other posts but the ones I saw look really great, creative. Nice work!

#include <iostream>
#include <ctime>

void PrintIntroduction(int Difficulty)
{
    // ASCII artwork, wish it was cooler
    std::cout << "\n\n";
    std::cout << R"(               M   M          A      TTTTTTTT    H      H
              M M M M        A A        T        H      H
             M   M   M      AAAAA       T        HHHHHHHH
            M         M    A     A      T        H      H
           M           M  A       A     T        H      H
         ===================================================
34580398*12371203987^3890*3409+5389=110^590/340459-123980:7753908+34568=6
========================================================================= 
W             W    IIIIIII    ZZZZZZZ         A         RRRRR      DDDDDD
 W           W        I            Z         A A        R    R     D     D
  W         W         I           Z         AAAAA       RRRRR      D      D
   W   W   W          I          Z         A     A      R   R      D      D
    W W W W           I         Z         A       A     R    R     D     D
     W   W         IIIIIII     ZZZZZZZZ  A         A    R     R    DDDDD  )" << '\n';
    // The game starts, meet the math wizard
    std::cout << "\n\nTremble mortal knave, for I am MATH WIZARD! Lord of arithmetical terror!\n";
    std::cout << "Prove that your wretched life is worth sparing through a level " << Difficulty;
    std::cout << " TRIAL by INTEGER!\nIf you fail, I shall subject you to a fate most terrible to behold...\n";
    std::cout << "MUHAHAHAHA!!!\n\n";
}

bool PlayGame(int Difficulty, int MaxDiff)
{
    PrintIntroduction(Difficulty);

    //Declare 3 number code
    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;

    // Print CodeSum and CodeProduct to the terminal
    std::cout << "To beat me name these numbers three...";
    std::cout << "\nThose which are the sum of " << CodeSum; 
    std::cout << "\nAnd those which yield the product of " << CodeProduct << '\n'; 

    //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 guess is correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        if(Difficulty != MaxDiff)
        {
            std::cout << "\nDrat! Perhaps you are not entirely the buffoon you seem."; 
            std::cout << "\nLet us see how you fare in the NEXT TRIAL!";
        }    
        return true;
    }
    else
    {
        std::cout << "\nWRONG! BAHAHAHA!!!";
        std::cout << "\nOhh noo!! MATH WIZARD has transformed you into an irrational number!";
        std::cout << "\n\nRecover your dignity and try again!";
        return false;
    }
}

int main()
{
    srand(time(NULL));
    int LevelDifficulty = 1;
    int const MaxDifficulty = 5;

    while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels completed
    {
        bool bLevelComplete = PlayGame(LevelDifficulty, MaxDifficulty);
        std::cin.clear(); // Clears any errors
        std::cin.ignore(); // Discards the buffer

        if (bLevelComplete)
        {
            ++ LevelDifficulty; 
        }          
    }
        std::cout << "\n...";
        std::cout << "\n\nWHAT!? No more trials!? But how could you-- no, wait! NOOOO!!!";
        std::cout << "\n*MATH WIZARD explodes*";
        std::cout << "\nIncredible! You have bested the MATH WIZARD!";

    return 0;
}

    

2 Likes
#include <iostream>

void PrintIntroduction(int Difficulty)
{
    std::cout << "You wake up. Just another day. Just the same boring, depressing day as every day in the last few months.\n";
    std::cout << "But today is different. You feel like you can overcome this feeling of not belonging.\n";
    std::cout << "You now there's something on your mind that repress your memories, the memories when everything happened and make you the way you are today.\n";
    std::cout << "With that in mind, you start making an effort to remember everything, and try to come to terms with that.\n";
    std::cout << "Each level in this game represents a step closer to freedom. Each step would be more difficult than the last one\n";
    std::cout << "You must guess three numbers to crack your mental code and unlock a memory. Go on! Be strong!\n";
    std::cout << "Level " << Difficulty << std::endl;
}

bool PlayGame(int Difficulty)
{
    //Game plot background before the game starts.
    PrintIntroduction(Difficulty);

    //Declare 3 number code
    const int CodeA = 4;
    const int CodeB = 10;
    const int CodeC = 13;

    //Sum and product of the previously declared number codes.
    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";
    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 << "\nYou regain another memory from your past. Keep going, you're closer to freedom! \n\n";
        return true;
    }
    else
    {
        std::cout << "\nYou spend another year trying to figuring out what went wrong. Not everything is lost, keep trying! \n\n";
        return false;
    }
}

int main()
{
    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;
    while (LevelDifficulty <= MaxDifficulty) //Loop game until all levels completed
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear();
        std::cin.ignore();

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
    }
    std::cout << "You remembered everything and overcame every challenge in front of you. You feel... FREEDOM!";
    return 0;
}

Nothing fancy about it, and no problems at all coding the game.

2 Likes

Great Work!

1 Like

#include
void PrintIntroduction(int Difficulty) {
std::cout << “\n\nYou are a man searching for a level " << Difficulty;
std::cout << " treasure chest…\nYou need to enter the correct code to continue…\n\n”;
}

bool PlayGame(int Difficulty){
PrintIntroduction(Difficulty);

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\n”;
std::cout << "\n+ The codes add up to: " << CodeSum;
std::cout << "\n+ The codes multiply to give: " << CodeProduct;
//Store Player Guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;

int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if (GuessSum == CodeSum && GuessProduct == CodeProduct) {
std::cout << “\nCongratulations, you have moved on to the next treasure chest”;
return true;
}
else {
std::cout << “\nTry again!”;
return false;
}
}

int main()
{
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
while(LevelDifficulty<=MaxDifficulty) {
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();//Clears any errors
std::cin.ignore();//Discards the buffer
if (bLevelComplete) {
++LevelDifficulty;
}
}
std::cout << “Congratulations! You have found all treasure chests”;
return 0;
}

Here’s my code, sorry for not being too creative regarding the messages.

1 Like

I got a level indicator to work, it was less tricky than I thought, but more than I hoped.
Free motor oil for everybody!

#include <iostream>

void PrintIntroduction(int Difficulty)
{
    // this prints a message to the terminal
    std::cout << "\n* You are a rookie bomb-defuser robot.\n";
    std::cout << "* You are about to defuse your first level " << Difficulty << " bomb,";
    std::cout << "\nyour circuitry is sweaty. Dont Explode!" << std::endl;
    std::cout << std::endl;
    std::cout << "* You need to enter the correct code to continue...\n";
}

bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);

    //declare three number code
    const int CodeA = rand();
    const int CodeB = rand();
    const int CodeC = rand();

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

    //Print CodeSum and product to the terminal
    std::cout << std::endl;
    std::cout << "+ There are three numbers in the code";
    std::cout << "\n+ The codes add up to: " << CodeSum;
    std::cout << "\n+ The codes multiply to give: " << CodeProd << std::endl;

    std::cout << std::endl;
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA;
    std::cin >> GuessB;
    std::cin >> GuessC;

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


    //Check if player guess is correct
    if (GuessSum == CodeSum && GuessProd == CodeProd)
    {
        std::cout << "\n* Success! You are the greatest hero!\n";
        std::cout << "Move on to the next level, cool machine!\n";
        return true;
    }
    else
    {
        std::cout << "\n* Oh no! You exploded! There are wires everywhere!\n";
        std::cout << "Try again!\n";
        return false;
    }

    std::cout << "\n\n+ The sum of your guesses is " << GuessSum;
    std::cout << "\n+ Your guesses multiplied together is " << GuessProd;
}

int main()
{
    int LevelDifficulty = 1;

    int const MaxLevel = 4;

    while (LevelDifficulty <= MaxLevel) // Loops game until levels completed
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear(); // Clears errors
        std::cin.ignore(); // Discards buffer

        if (bLevelComplete)
        {
            ++LevelDifficulty;

            if (LevelDifficulty <= MaxLevel)
            {
                std::cout << "\n******************** Level " << LevelDifficulty << " ********************\n";
            }
        }
        
    }

    std::cout << "\nAll of the bombs have been difused!\n";
    std::cout << "You have earned some delicous motor oil!\n";
    std::cout << "Don't spend it all in one place, you little rascal!\n";
    
    return 0;
}

Don’t spend it all in one place, you rascals!

1 Like

My game so far:

#include <iostream>

void PrintIntroduction(int Difficulty)
{
    std::cout << "\n\nYou're imprisoned within an alien ship, where you've been tortured for several days. Out of the blue, one of the guards comes to you. He says he'll set you free and even give you access to an escape capsule, in order to warn mankind about the upcoming invasion, on one condition; For him to know you're smart enough to use one of the capsules properly, you must answer correctly to some math riddles... ";
    std::cout << "\n"; 
    std::cout << "\nThe riddle number " << Difficulty << " goes as follows...";
}

bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);
    
    // NumberC = 0; 

    
    int NumberA = 6;
    int NumberB = 4;
    int NumberC;
    NumberC = 3;

    // NumberB = 13;

    //NumberA=1; 

    int SumABC = NumberA + NumberB + NumberC;
    int ProdABC = NumberA * NumberB * NumberC;

    NumberA=1; 

    //print the prod and addition to the cmd
    std::cout << "\n";
    std::cout << "There were 3 numbers..." << "\n";
    std::cout << "Those numbers add-up to: " << SumABC << "\n";
    std::cout << "Those numbers multiply to: " << ProdABC << "\n";
    
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;
    //std::cin >> GuessB;
    //std::cin >> GuessC;
    //std::cout << GuessA << GuessB << GuessC;
    
    int SumGuess = GuessA + GuessB + GuessC;
    int ProdGuess = GuessA * GuessB * GuessC;

    if(SumGuess == SumABC && ProdGuess == ProdABC)
    {
        std::cout << "You've nailed it!";
        return true;
    }
    else
    {
        std::cout << "You've lost and are forever doomed to see youself rott and your species perish from within your cell";
        return false;
    }
    
    //std::cout << SumGuess;
    //std::cout << ProdGuess;
}

int main()
{
    int LevelDifficulty = 1;
    int const MaxLevel = 7;
    while(LevelDifficulty <= MaxLevel)
    {
        bool bLevelCompleted = PlayGame(LevelDifficulty);
        //PlayGame();
        std::cin.clear();
        std::cin.ignore();

        if(bLevelCompleted)
        {
            ++LevelDifficulty;
        }
        else
        {
            //break;
            //LevelDifficulty = MaxLevel + 1;
            return 0;
        }
        
    }
    std::cout << "\nYou've succesfully completed all the riddles!, you're now free to go save humanity";
    //signal that everything ran as planned :)
    return 0;
}

I know it’s kinda messy, but i comment out a lot of things i had doubts about, or other possible alternatives to the same problem. Good luck with your games fellows, see you around! (btw, my game doesn’t allow mistakes, if you lose one of the riddles you’ve got to start all over again)

#include
void ASCII()
{
std::cout << R"(
.----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------.
| .--------------. || .--------------. || .--------------. || .--------------. | | .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |
| | ____ | || | ______ | || | _______ | || | _________ | | | | ___ | || | _____ _____ | || | _________ | || | _______ | || | _________ | |
| | .’ . | || | .' ___ | | || | |_ __ \ | || | |_ ___ | | | | | .' '. | || ||_ _||_ _|| || | |_ ___ | | || | / ___ | | || | | _ _ | | | | | / .--. \ | || | / .' \_| | || | | |__) | | || | | |_ \_| | | | | / .-. \ | || | | | | | | || | | |_ \_| | || | | (__ \_| | || | |_/ | | \_| | | | | | | | | | || | | | ____ | || | | __ / | || | | _| _ | | | | | | | | | || | | ' ' | | || | | _| _ | || | '.___-. | || | | | | |
| | \ --' / | || | \.] | | || | | | \ _ | || | | |/ | | | | | \ -' \_ | || | \–’ / | || | | |/ | | || | |\____) | | || | _| |_ | | | |..’ | || | ._____.' | || | |____| |___| | || | |_________| | | | |.._| | || | `..’ | || | || | || | |.’ | || | |__| | |
| | | || | | || | | || | | | | | | || | | || | | || | | || | | |
| ‘--------------’ || ‘--------------’ || ‘--------------’ || ‘--------------’ | | ‘--------------’ || ‘--------------’ || ‘--------------’ || ‘--------------’ || ‘--------------’ |
‘----------------’ ‘----------------’ ‘----------------’ ‘----------------’ ‘----------------’ ‘----------------’ ‘----------------’ ‘----------------’ ‘----------------’
)"<< std::endl;
}
void PrintIntroduction(int Difficulty)
{
ASCII();

//Print welcome messages to the terminal
std::cout << "You are at an Orc’s hideout and come to a gate, with a lock on it that reads “Lv .” << Difficulty;
std::cout << “\n The sound of tortured screams can be heard from the other side.\n”;
std::cout << “You are worried about your partner, who got captured by the orcs, but keep your composure trying to unlock the gate.\n”;
std::cout << “You need to enter the correct numbers into the lock to move forward…\n”;
std::cout << “The runes on the lock reads, “If thou wishes to pass, show thy knowledge and discover the sum and product of the numbers three”.\n\n”;
}

bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);

//Declare 3 number code
int const NumA = 4;
int const NumB = 3;
int const NumC = 2;

//Calculate the sum and product formulas
int const NumSum = NumA + NumB + NumC;
int const NumProduct = NumA * NumB * NumC;

//Print sum and product to the terminal
std::cout << std::endl;
std::cout << "There are 3 numbers on the lock.\n";
std::cout << "The numbers add up to: " << NumSum << std::endl;
std::cout << "The numbers multiply to: "<< NumProduct << std::endl;

//Store Player Guess
int GuessA, GuessB, GuessC;

std::cout << "Give thy answer...: ";
std::cin >> GuessA >> GuessB >> GuessC;

std::cout << "You answered: " << GuessA << GuessB << GuessC << std::endl;

//GuessSum and GuessProduct code line
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;

//Check if the players guess is correct
if (GuessSum == NumSum && GuessProduct == NumProduct)
{   
    std::cout << "Thou are correct, you may pass...\n";
    return true;
}
else
{
    std::cout << "Thou are wrong, you cannnot pass...\n";
    return false;
}

}

void SecondaryDialogue()
{
std::cout << std::endl;
std::cout << “You enter the next corridor to find that there are some opened cells.\n”;
std::cout << “There are stains of blood covering the inside of each cell, and some small rats knawing on what was left of whoever was in there. \n”;
std::cout << “You hear the sound of foot steps coming closer and hide behind a nearby barrel. \n”;
std::cout << “Some orcs pass by, and you over hear one of them say, " Those prisoners are nosier then the last batch. Good thing they’re 6 blocks down so we can’t hear them as well form here” \n";

}

int main()
{
int LevelDifficulty = 1;
int const MaxLevel = 10;

while (LevelDifficulty <= MaxLevel) // Loop Game until all levels are completed
{ 
    bool bLevelComplete = PlayGame(LevelDifficulty);
    SecondaryDialogue(); 
    std::cin.clear(); //Clears any errors
    std::cin.ignore(); //Discards the buffer

    if (bLevelComplete)
    {   
        ++LevelDifficulty;
    }
    
}
int EndMessage (LevelDifficulty == MaxLevel)

    std::cout << "You got through all the doors and find your partner.\n";
    std::cout << "The sound of footsetps can be heard coming from the hallway.\n";
    std::cout << "You release all the prisoners and grab your partner to escape from the fortress.\n\n";
    std::cout << "There were many orcs, but you and the rest of the prisoners managed to escape.\n";
    std::cout << "One person was able to seal the opening to the fortress by causing the front of the fortress to collapse with an oil bomb.\n";
    std::cout << "Your partner recovers and the two of you enjoy the rest of your days adventuring for the rest of your days.\n\n";
    std::cout << "THE END";

return 0;

}

Pretty happy with the program, definitely learned a lot and can’t wait to see what’s coming next.

1 Like



1 Like

Here is my latest edit of the triplex game:

I’ve cleaned up the code and story a bit.

1 Like

I love the level indicator!

I thy like it thee!

This is where I’m at…

// Preprocessor Directive
#include <iostream>  

void GameIntro(int Difficulty)
{
    // Expression Statements - Print welcome messages to terminal
    std::cout << "\n\nTRIPLE X - ELITE HACKER SIMULATION\n";
    std::cout << " ______________\n";
    std::cout << "||            ||\n";
    std::cout << "||            ||\n";
    std::cout << "||            ||\n";
    std::cout << "||            ||\n";
    std::cout << "||____________||\n";
    std::cout << "|______________|\n";
    std::cout << " \\############\\" << std::endl;
    std::cout << "  \\############\\" << std::endl;
    std::cout << "   \\     ____   \\" << std::endl; 
    std::cout << "    \\____\\_\\___\\"<< std::endl;
    std::cout << "\n\nYou are a secret agent breaking in a level " << Difficulty;
    std::cout << "\nsecure server room... Enter the correct code to continue...\n\n";
}

void WinGame ()
{
    std::cout << "\n\nYou have opened the final door. Congratulations.\n";
}

bool PlayGame(int Difficulty)
{
    GameIntro(Difficulty);
    
    // Declaration Statements - 3 Number Code
    const int CodeA = 2;
    const int CodeB = 3;
    const int CodeC = 4;

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

    // More Expression Statements - Print sum and product to terminal
    std::cout << std::endl;
    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: " << CodeProduct;

    //Store and Return Guesses
    int GuessA, GuessB, GuessC;

    std::cout << "\nWhat is your guess?\n";
    std::cin >> GuessA >> GuessB >> GuessC;
    std::cout << "\nYou entered: " << GuessA << GuessB << GuessC;

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

    std::cout << std::endl;
    std::cout << "\nThe numbers you entered add up to: " << GuessSum;
    std::cout << "\n... and multiply to: " << GuessProduct;

    //Check if guess is accurate
    if(GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\nYou made it through this level!\n";
        return true;
    }

    else
    {
        std::cout << "\n\nYOU LOSE. TRY AGAIN!!!\n";
        return false;
    }

    WinGame();
}

// Main Function
int main()
{
    int LevelDifficulty = 1;
    const int MaxLevel = 5;

    while (LevelDifficulty <= MaxLevel) // Loop game until all levels are complete
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear();   // Clears any errors
        std::cin.ignore();  // Discards the buffer

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }
    
    WinGame();

    // Return Statement - End program
    return 0;
}
1 Like

1 Like

Privacy & Terms