Triple X Final Game

Just finished section 2 of the UE4 Course and I learned lots about C++ Programming. I present you Triple X in my own story.

#include <iostream>
#include <ctime>
void PrintIntroduction (int Difficulty)
{
    //Display the story to the player
    std::cout << "You are a WW3 soldier in a nuclear power plant of level " << Difficulty;
    std::cout << " danger... \nEnter the hidden code to start the shutdown sequence which stops the explosion...\n\n";
}

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

    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;

    //Display the CodeSum and the CodeProduct
    std::cout << "+ There are 3 numbers in the code";
    std::cout << "\n+ The code adds up to: " << CodeSum;
    std::cout << "\n+ The code multiply to give: " << CodeProduct << std::endl;

    //Store the player's guess
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;

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

    //Check if the Guess is correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct) 
    {
        std::cout << "\nGreat work! You succeeded in starting the shutdown sequence for the nuclear power plant. Move on to the next one!\n\n";
        return true;
    }
    else 
    {
        std::cout << "\nYou failed to stop the explosion! Try again!\n\n";
        return false;
    }
}

int main()
{   

    srand(time(NULL)); //create new random sequence based on the time of the day

    int LevelDifficulty = 1;
    int const MaxDifficulty = 5;

    while (LevelDifficulty <= MaxDifficulty) //This loopp while continue until all levels are complete
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear();
        std::cin.ignore();

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }
    std::cout << "Congrats! you successfully shutted down all 3 nuclear power plants. You saved your Country! We're all proud of you!\n\n";
    return 0;
}
1 Like

Congratulations on completing your Triple X game.

Privacy & Terms