My Triple X code

#include <iostream>
#include <ctime>

void PrintIntroduction(int Dificulty)
{
    system("CLS");
    //Print welcome messages to the terminal
    std::cout << "You are a secret agent breaking into a level " << Dificulty << " secure server room  " "...\n";    
    std::cout << "You need to enter the correct codes to continue...\n\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|   [1]   [2]   [3]   |";
    std::cout << "\n|                     |";
    std::cout << "\n|   [4]   [5]   [6]   |";
    std::cout << "\n|                     |";
    std::cout << "\n|   [7]   [8]   [9]   |";
    std::cout << "\n|                     |";
    std::cout << "\n|_____________________|";

}

void PrintWin(int Dificulty)
{
    system("CLS");
    std::cout << "Level: "<< Dificulty <<"\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|   [1]   [2]   [3]   |";
    std::cout << "\n|                     |";
    std::cout << "\n|   [4]   [5]   [6]   |";
    std::cout << "\n|                     |";
    std::cout << "\n|   [7]   [8]   [9]   |";
    std::cout << "\n|                     |";
    std::cout << "\n|_____________________|";        

    std::cout << "\n\nPiiii... You unlocked that room! Lets go to the next one!.\n";
}

void PrintLose(int Dificulty)
{
    system("CLS");
    std::cout << "Level: "<< Dificulty <<"\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|   [1]   [2]   [3]   |";
    std::cout << "\n|                     |";
    std::cout << "\n|   [4]   [5]   [6]   |";
    std::cout << "\n|                     |";
    std::cout << "\n|   [7]   [8]   [9]   |";
    std::cout << "\n|                     |";
    std::cout << "\n|_____________________|";

    std::cout << "\n\nBzzzz. Wrong code. Try Again.\n";
}

void PrintCompletedGame()
{
    system("CLS");
    std::cout << "\n ___  ___         ___   __       _____                   _____    ___         ___ "; 
    std::cout << "\n|    |   | |\\  | |  _  |  \\   /\\    |   |   | |      /\\    |   | |   | |\\  | |    ";
    std::cout << "\n|    |   | | \\ | |   | |  /  /- \\   |   |   | |     /- \\   |   | |   | | \\ |  ---"; 
    std::cout << "\n|___ |___| |  \\| |___| |  \\ /    \\  |   |___| |___ /    \\  |   | |___| |  \\|  ___|"; 

    std::cout << "\n\nGreat work, Agent! You got all the files. Now get out of there!\n";
}

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

    //declare 3 number code
    const int CodeA = rand() % Dificulty + Dificulty;
    const int CodeB = rand() % Dificulty + Dificulty;
    const int CodeC = rand() % Dificulty + Dificulty;

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

    //print CodeSum and CodeProduct 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 give: " << CodeProduct;
    
    int GuessA, GuessB, GuessC;

    std::cout << "\n\nEnter the code: ";
    std::cin >> GuessA >> GuessB >> GuessC;

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

    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {        
        PrintWin(Dificulty); 
        std::cin.ignore(); //discards buffer
        return true;
    } 
    else
    {
        PrintLose(Dificulty);
        std::cin.ignore(); //discards buffer
        return false;
    }    
}

int main()
{   
    srand(time(NULL)); //random seed 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();  //clear any errors
        std::cin.ignore(); //discards buffer        

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
    }

    PrintCompletedGame();
    
    return 0;
}```
1 Like

Awesome code!

Privacy & Terms