TripleX (Escape Room: Master Lock) Showcase

This is my result of the TripleX terminal game. I have added some ASCII art to make it all look a bit more nice.


Here is my code:

#include <iostream>
#include <ctime>


void PrintIntroductionArt(int Difficulty)
{
    std::cout << R"(
---------------------------------------------------------------------------------
=====================================ESCAPE ROOM=================================
---------------------------------------------------------------------------------
                                     .--------.
                                    / .------. \
                                   / /        \ \
                                   | |        | |
                                  _| |________| |_
                                .' |_|        |_| '.
                                '._____ ____ _____.'
                                |     .'____'.     |
                                '.__.'.'    '.'.__.'
                                '.__  |MASTER|  __.'
                                |   '.'.____.'.'   |
                                '.____'.____.'____.'LOCK
                                '.________________.'
---------------------------------------------------------------------------------
=================================================================================
---------------------------------------------------------------------------------
    )" << '\n';
    std::cout << "You wake up and find yourself trapped in a level "<< Difficulty;
    std::cout << " escape room.\nYou look around and notice that the room is completely empty,\n";
    std::cout << "but there is a 3 digit lock on the door.\n";
    std::cout << "You need to enter the correct codes to continue...\n";
    std::cout << std::endl;
}

bool PlayGame(int Difficulty)
{
    //Print welcome messages to the terminal
    PrintIntroductionArt(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 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 give: " << CodeProduct << std::endl;
    std::cout << std::endl;

    // Store PlayerGuess
    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 << std::endl;
        std::cout << "Congratulations, you have entered the correct code.\n";
        return true;
    }

    else
    {
        std::cout << std::endl;
        std::cout << "Oh no!!!!\n";
        std::cout << "Unfortunately the code did not work, it seems like your trapped in here forever!\n";
        return false;
    }

}

int main()
{
    srand(time(NULL)); // create new random sequence based on time of day

    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;

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

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }

    std::cout  << "\n********* Good job, you have managed to escape from all rooms. You Win! *********\n";
    std::cout << R"(
                                    _____________
                                   /      _      \
                                   [] :: (_) :: []
                                   [] ::::::::: []
                                   [] ::::::::: []
                                   [] ::::::::: []
                                   [] ::::::::: []
                                   [_____________]
                                       I     I
                                       I_   _I
                                        /   \
                                        \   /
                                        (   )   
                                        /   \
                                        \___/
    )" << '\n';

    return 0;
}
1 Like

Thanks for sharing. I like the ASCII art.

Well done! Really good job with the ASCII art!