My Version of TripleX

Seems to work. My difficulty level remains as is for my nephew to play with :slight_smile:
Oh and I need to add more comments…

#include <iostream>
#include <ctime>

void PrintIntroduction(int Difficulty)
{
    std::cout << "\n";
    std::cout << "\n";
    std::cout << "       SPACE CARGO WAGON   \n";
    std::cout << "              AI   \n";
    std::cout << "     _______ /  \\_________\n";
    std::cout << "    | __________________  |\n";
    std::cout << "    ||    AUTO PILOT    |_|\n";
    std::cout << "    ||                  |O|\n";
    std::cout << "    ||.;',`' SELF .`~,;'|O|\n";
    std::cout << "    ||':'' DESTRUCT :'`'|o|\n";
    std::cout << "    ||.:',~; CODE .,:'`;|_|\n";
    std::cout << "    ||                  | |\n";
    std::cout << "    ||  CARGO: X100TR   | |\n";
    std::cout << "    |'------------------' |\n";
    std::cout << "----'---------------------'----\n";
    std::cout << "\n\n";

    std::cout << "You have just boarded an abandoned space cargo wagon which is in auto destruct mode." << std:: endl;
    std::cout << "You need to enter the correct Level " << Difficulty << " codes to stop the auto destruct and get the cargo." << std::endl;
}

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

    const int CodeA = rand() % Difficulty + 1;
    const int CodeB = rand() % Difficulty + 1;
    const int CodeC = rand() % Difficulty + 1;
    
    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    std::cout << std::endl;
    std::cout << "The onboard computer, SCWAI, says \'To stop auto destruct, enter the correct three digits.\'\n";
    std::cout << "The codes add up to: " << CodeSum << "\n";
    std::cout << "The codes multiply to give: " << CodeProduct << "\n";

    int GuessA, GuessB, GuessC, GuessSum, GuessProduct;

    const int TotalTries = 3;
    int TriesRemaining = 0;
    while(TriesRemaining < TotalTries)
    {
        std::cin >> GuessA >> GuessB >> GuessC;
        std::cout << "You entered " << GuessA << " " << GuessB << " " << GuessC << "\n";
        GuessSum = GuessA + GuessB + GuessC;
        GuessProduct = GuessA * GuessB * GuessC;
        std::cout << "The sum is " << GuessSum << "\n";
        std::cout << "The product is " << GuessProduct << "\n";

        if(GuessSum == CodeSum && GuessProduct == CodeProduct)
        {
            std::cout << "Woop Woop! Self destruct for Level " << Difficulty << " has been disabled.\n";
            return true;
        }
        else
        {
            ++TriesRemaining;
            std::cout << "Incorrect. Try again. You have " << TotalTries - TriesRemaining << " tries remaining. \n";
        }
    }

    return false;
}

int main()
{
    srand(time(NULL));
    
    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;
    while (LevelDifficulty <= MaxDifficulty)
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);

        std::cin.clear();
        std::cin.ignore();

        if(bLevelComplete)
        {
            // increase the level difficulty
            ++LevelDifficulty;            
        }
        else
        {
            std::cout << "YOU LOSE SUCKER  -  KABOOMMMMMM";
            return 0;
        }
        
    }
    
    //std::cout << "YOU GET THE CARGO!";

    return 0;
}
1 Like

Awesome job! :clap::clap:

Privacy & Terms