Triple X: The Dark Room Edition Showcase

So I just finished off the lessons for TripleX, I’m still yet to tinker around. I did add another void function for the ASCII with static. But I guess I could have done that in the PrintIntroduction?

TripleX Code
#include <iostream>
#include <ctime>

void ASCII()
{
    // Run once
    static const auto runOnce = []{
    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|__________|";
    
    return true;
    }();
}

void PrintIntroduction(int Difficulty)
{
// Print welcome messages to terminal
    ASCII();
    

std::cout << "\n\n----------------------------------------------------------------------------------------";

    std::cout << "\n\nYou wake, to find yourself in a dark room!"; 
    std::cout << " You are on floor " << Difficulty;
    std::cout << ". Do you dare try to escape?\n";

std::cout <<"\n----------------------------------------------------------------------------------------";
}

bool PlayGame(int Difficulty)
{

    PrintIntroduction(Difficulty); 

    // Declare 3 number
    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 product to the terminal
    std::cout << "\n\n+ There are 3 numbers in the code";
    std::cout << "\n+ The codes add-up to: " << CodeSum;
    std::cout << "\n+ The codes multiply to: " << CodeProduct << "\n";

    //Store player guess
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA;
    std::cin >> GuessB;
    std::cin >> GuessC;
    std::cout << "You entered: " << GuessA << GuessB << GuessC; 

    //Declare guess sum and product
    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;
    std::cout << "\n";
   
   //Guess sum true or false
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
    std::cout << "\n***I knew you could be somewhat competent...***";
    return true;
}
else
{
    std::cout << "\n***You caress the walls, it feels dirty from your unwanted hands. Find the code box!***";
    return false;
}

}

int main()
{
    srand(time(NULL)); //Create new random sequence base on time of day
    int LevelDifficulty = 1;
    int const MaxDifficulty = 5;

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

        if (blevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }

    std::cout <<"\n   ______________";
    std::cout <<"\n |\ ___________ /|";
    std::cout <<"\n | |  /|,| |   | |";
    std::cout <<"\n | | |,x,| |   | |";
    std::cout <<"\n | | |,x,' |   | |";
    std::cout <<"\n | | |,x   ,   | |";
    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\n***You burst out the door, the light hits your eyes."; 
    std::cout << "\nYou have escaped the dark room.***";
    return 0;
}
1 Like

I love the door ASCII art!

Privacy & Terms