My Version of Triplex Game :)

#include <iostream>
#include <ctime>

void WelcomeMessage()
{           
    //Initial welcome message, only prints once per game session
    std::cout << 12 % 7;
    std::cout << "\n\n====== WELCOME TO TRIPLEX ======\n";
    std::cout << "================================\n\n";
    std::cout << "\nYou must enter the correct codes to disable the bombs, god speed.\n\n";

}

void PrintIntro(int Difficulty)
{
    //Message to disarm & difficulty level of bomb
    std::cout << "\nEnter the correct codes to disable the level " <<  Difficulty <<  " bomb.\n";
}

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

    //Intializes disarm code for bomb  
    const int CodeA = rand() % Difficulty + Difficulty; 
    const int CodeB = rand() % Difficulty + Difficulty;
    const int CodeC = rand() % Difficulty + Difficulty;              

    //Sum & product of 3 code numbers
    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    //Prints sum & product of the 3-number code to terminal
    std::cout << "\n* There are 3 numbers in the code.";
    std::cout << "\n* The sum of all 3 numbers is: " << CodeSum;
    std::cout << "\n* The product of all 3 numbers is: " << CodeProduct << "\n\n";

    //Gets player guesses, adds for sum, and multiplies for product
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;

    std::cout << "\nYou entered: " << GuessA << " " << GuessB << " " << GuessC << "\n";

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

    //Checks if player won or lost and informs player of the results
    if(GuessSum==CodeSum && GuessProduct==CodeProduct)
    {
        std::cout << "\nYOU GOT IT RIGHT!!!\n\n-----<0>-=o=-<0>------\n\nNEXT LEVEL BOMB IN SIGHT!!!" << std::endl;
        return true;
    }
    else
    {
        std::cout << "\nBOOOOOOM!!!\n"; 
        std::cout << "\nYou lose!!!\n\nTry again, same bomb." << std::endl;
        return false;
    }
}

int main() 
{
    WelcomeMessage();
    srand (time(NULL)); //Ensures randomization based on TOD when generated
    int LevelDifficulty = 1;
    const int MaxLevel = 3;
    while (LevelDifficulty <= MaxLevel) // Loops game until all levels are completed
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);  //Initializes "Difficulty" variable, kinda confusing-ish?
        std::cin.clear(); //Clears any user input errors
        std::cin.ignore(); //Discards the buffer
        if (bLevelComplete)
        {
            ++LevelDifficulty; //Increases diffculty after each bomb is successfully disarmed
        }   
    }

    //Game winning message, only prints when final bomb is disarmed
    std::cout << "\n\n==========================\nYOU WIN ALL THE THINGS!!!\n==========================\n\n";
    return 0;
}
2 Likes

Nice version! :smile:

1 Like

Thanks man appreciate it! :slight_smile:

1 Like

Of course anytime!

–This is my version of Triple X.

1 Like

Privacy & Terms