TripleX Game and TripleX Solver

Hey guys!

I pretty much never post on anything, but I’m going to try to change that. I went through some basic Unity Tutorials a few years ago, but life happened and I had to give up learning for a while. I’ve done a few coding tutorials, but when it gets to the part where you finish and they say “now solve a problem you have with code!” I tend to blank. Trying to make a game is different. It’s much easier problem for me to try breakdown into components. I probably spent less than 100 hours in Unity trying to make my own game, but I learned a lot.

Below is my take on the “TripleX” tutorial game for Unreal C++. I spent a some extra time making it a little more interesting, but it’s really not too different that anybody elses.

Also, as an exercise I thought I would try to make a program that would solve the problems TripleX wanted you to solve. That code is below the games code. It works, but you end up with a lot of duplicate answers, and is hard coded to a max number of 12 as one of your individual numbers. I thought about cleaning it up, but I it’s probably time to just move on to Unreal for now.

// TripleX Game Based on Udemy Course "Unreal Engine Developer: Learn C++ and Make Video Games
// 6/27/2020

#include<iostream> //Preprocessor Directive
#include<ctime> //Time access

void PrintIntro(int Difficulty)
{
    std::cout << "\nYou are a secret agent breaking into a level " << Difficulty << " secure server room...";    //Expression statement
    std::cout << std::endl;                                                         //    << = Insertion Operator
    std::cout << "Enter the correct code to continue..." << std::endl;
}

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

    // Set Player Lives
    int PlayerLives = 3;

    // Randomize Code
    const int CodeA = rand() % (1 + (Difficulty * 2) ) + 1;     //Declaration Statements
    const int CodeB = rand() % (1 + (Difficulty * 2) ) + 1;
    const int CodeC = rand() % (1 + (Difficulty * 2) ) + 1;

    // Calculate Answers
    int CodeSum = CodeA + CodeB + CodeC;
    int CodeProduct = CodeA * CodeB * CodeC;

    // Store Player Guesses
    int PlayerGuessA;
    int PlayerGuessB;
    int PlayerGuessC;

    while(PlayerLives > 0)
    {
        // Print CodeSum and CodeProduct to the terminal
        std::cout << "\n+ There are 3 numbers in the code.";           //Expression Statements
        std::cout << "\n+ The codes add-up to: " << CodeSum;
        std::cout << "\n+ The codes multiply to give: " << CodeProduct << std::endl;

        // Get Player Guesses
        std::cout << "\nGuess the 3 digits: ";
        std::cin >> PlayerGuessA >> PlayerGuessB >> PlayerGuessC;

        int PlayerGuessSum = PlayerGuessA + PlayerGuessB + PlayerGuessC;
        int PlayerGuessProduct = PlayerGuessA * PlayerGuessB * PlayerGuessC;


        // Is the Player right?
        if(PlayerGuessSum == CodeSum && PlayerGuessProduct == CodeProduct ) 
        {                                                               //Begin Code Block
            std::cout << "\n*****************************************************************************************";
            std::cout << "\n***Looks like that was the right code. Great job!***\n";
            std::cout << "\n*****************************************************************************************";

            // End PlayGame() with a correct answer
            return true;
        }                                                               //End Code Block

        // If Player is wrong
        else
        {
            PlayerLives--;                                              // Remove 1 life if incorrect answer given

            // Incorrect answer output
            if(PlayerLives > 1)
            {
                std::cout << "\n*****************************************************************************************";
                std::cout << "\n***The Server buzzes angrily! It does not like what you are doing.***\n";
                std::cout <<   "***Try again.***\n";
                std::cout << "\n*****************************************************************************************";

            }
            // Last life output           
            else if(PlayerLives == 1)            
            {
                std::cout << "\n*****************************************************************************************";
                std::cout << "\n***Red lights illuminate the room. A voice from somewhere in the room begins speaking.***\n";
                std::cout << "***\"Multiple errors dectected. Initializing MandatoryBedtime.exe...\"***\n";
                std::cout << "***You're pretty sure this is your last chance.***\n";  
                std::cout << "\n*****************************************************************************************";
              
            }
            // Game Over output              
            else if(PlayerLives <= 0)
            {             
                std::cout << "\n*****************************************************************************************";
                std::cout << "\n***Incorrect!!!***";
                std::cout << "\nThe correct answer was: " << CodeA << " " << CodeB << " " << CodeC << std::endl;
                std::cout << "\n\n***Alarms begin flashing, and the computer locks.***";
                std::cout << "\n***Gas begins filling the room, and you suddenly feel very sleepy...***\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 << "                              ud$$$**$$$$$$$bc.\n";
                std::cout << "                           u@**\"        4$$$$$$$Nu\" \n";
                std::cout << "                          J                ""#$$$$$$r \n";
                std::cout << "                         @                       $$$$b\n";
                std::cout << "                       .F                        ^*3$$$\n";
                std::cout << "                      :% 4                         J$$$N\n";
                std::cout << "                      $  :F                       :$$$$$\n";
                std::cout << "                     4F  9                       J$$$$$$$\n";
                std::cout << "                     4$   k             4$$$$bed$$$$$$$$$\n";
                std::cout << "                     $$r  'F            $$$$$$$$$$$$$$$$$r\n";
                std::cout << "                     $$$   b.           $$$$$$$$$$$$$$$$$N\n";
                std::cout << "                     $$$$$k 3eeed$$b    $$$Euec.\"$$$$$$$$$\n";
                std::cout << "       .@$**N.       $$$$$\" $$$$$$F'L $$$$$$$$$$$  $$$$$$$\n";
                std::cout << "       :$$L  'L       $$$$$ 4$$$$$$  * $$$$$$$$$$F  $$$$$$F         edNc\n";
                std::cout << "      @$$$$N  ^k      $$$$$  3$$$$*%   $F4$$$$$$$   $$$$$\"        d\"  z$N\n";
                std::cout << "      $$$$$$   ^k     '$$$\"   #$$$F   .$  $$$$$c.u@$$$          J\"  @$$$$r\n";
                std::cout << "      $$$$$$$b   *u    ^$L            $$  $$$$$$$$$$$$u@       $$  d$$$$$$\n";
                std::cout << "      ^$$$$$$.    \"NL   \"N. z@*     $$$  $$$$$$$$$$$$$P      $P  d$$$$$$$\n";
                std::cout << "         ^\"*$$$$b   '*L   9$E      4$$$  d$$$$$$$$$$$\"     d*   J$$$$$r\n";
                std::cout << "              ^$$$$u  '$.  $$$L     \"#\" d$$$$$$\".@$$    .@$\"  z$$$$*\"\n";
                std::cout << "               ^$$$$. ^$N.3$$$       4u$$$$$$$ 4$$$  u$*\" z$$$\"\n";
                std::cout << "                  '*$$$$$$$$ *$b      J$$$$$$$b u$$P $\"  d$$P\n";
                std::cout << "                     #$$$$$$ 4$ 3*$\"$*$ $\"$'c@@$$$$ .u@$$$P\n";
                std::cout << "                       \"$$$$  \"\"F~$ $uNr$$$^&J$$$$F $$$$#\n";
                std::cout << "                         \"$$    \"$$$bd$.$W$$$$$$$$F $$\"\n";
                std::cout << "                          ?k         ?$$$$$$$$$$$F'*\n";
                std::cout << "                           9$$bL     z$$$$$$$$$$$F\n";
                std::cout << "                             $$$$    $$$$$$$$$$$$$\n";
                std::cout << "                              '#$$c  '$$$$$$$$$\"\n";
                std::cout << "                              .@\"#$$$$$$$$$$$$b\n";
                std::cout << "                            z*      $$$$$$$$$$$$N.\n";
                std::cout << "                         e\"      z$$\"  #$$$k  '*$$.\n";
                std::cout << "                      .u*      u@$P\"      '#$$c   \"$$c\n";
                std::cout << "              u@$*\"\"\"       d$$\"            \"$$$u  ^*$$b.\n";
                std::cout << "            :$F           J$P\"                ^$$$c   '\"$$$$$$bL\n";
                std::cout << "            d$$  ..      @$#                      #$$b         '#$\n";
                std::cout << "            9$$$$$$b   4$$                          ^$$k         '$\n";
                std::cout << "            \"$$6\"\"$b u$$                             '$    d$$$$$P\n";
                std::cout << "             '$F $$$$$\"                              ^b  ^$$$$b$\n";
                std::cout << "              '$W$$$$\"                                'b@$$$$\"\n";
                std::cout << "                                                       ^$$$*  Gilo95'\n\n";
            }
            // Error prevention and dump
            else
            {
                std::cout << "\n*****************************************************************************************";
                std::cout << "I don't know how we got here...";
                std::cout << "\nThe answer was: " << CodeA << " " << CodeB << " " << CodeC << std::endl;
                std::cout << "Player answers were " << PlayerGuessA << " " << PlayerGuessB << " " << PlayerGuessC;
                std::cout << "\nPlayerLives = " << PlayerLives;
                std::cout << "\n\n";
                break;
            }
        }
    }
    // End Playgame() with loss
    return false;
}

int main() //Main Function
{
    //Intro
    std::cout << "\n\n**********************************************************************Created 6-27-2020**";
    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*****************************************************************************************";

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

    int LevelOfDifficulty = 1;
    int MaxDifficulty = 5;

    int Difficulty = 1;
    //Loop game until all levels are completed.
    while(LevelOfDifficulty <= MaxDifficulty)                 
        {
            bool bLevelComplete = PlayGame(LevelOfDifficulty);
            std::cin.clear();
            std::cin.ignore();

            //If you guess correctly increase difficulty and run game again.
            if(bLevelComplete)          
            {
                LevelOfDifficulty++;                            
            }       
            else
            {                
                break;
            }               

            if(LevelOfDifficulty > MaxDifficulty)
            {
                std::cout << "\n*****************************************************************************************";
                std::cout << "\n***You did it! You're in! You quickly navigate to your companies firewall settings.***";
                std::cout << "\n***Opening the command line you type: AddFirewallException https://www.everythingcrossstitch.com/***";    //maybe pull from a list of something silly
                std::cout << "\n***No longer will your companies oppresive webfilter deny you of your passion!***";
                std::cout << "\n***Scrubbing all records of your exploits you log out, and sneak out of the server room.***";
                std::cout << "\n***You smile to yourself as you leave the scene of the perfect crime.***\n\n";
                std::cout << "\n*****************************************************************************************";
            }
        }
    char AnyKey = 'y';
    std::cout << "Press any key then enter to continue.";
    std::cin >> AnyKey;
    return 0;           //Return Statement
}

And here is the SolveTriple code.

#include<iostream>

void main()
{
    std::cout << "\n****************************************************************\n";
    std::cout << "****************************************************************\n";
    std::cout << "This program will find the set of 3 numbers where the user knows\n";
    std::cout << "the product and sum of these 3 numbers. The numbers must be less\n";
    std::cout << "than 10.\n";

    bool ContinuePlay = true;

    while(ContinuePlay)
    {
        int SumToSolve = 0;
        int ProductToSolve = 0;

        int TestSum = 0;
        int TestProduct = 0;

        int s = 0;
        int p = 0;

        char YesNo = 'y';

        std::cout << "\nEnter Sum of the 3 numbers: ";
        std::cin >> SumToSolve;

        std::cout << "\nEnter Product of the 3 numbers: ";
        std::cin >> ProductToSolve;

        std::cout << "\nHere are the possible answers:\n";

        for( int FirstNumber = 0; FirstNumber <= 12; FirstNumber++)
        {
            for(int SecondNumber = 0; SecondNumber <= 12; SecondNumber++)
            {
                for(int ThirdNumber = 0; ThirdNumber <= 12; ThirdNumber++)
                {
                    TestSum = FirstNumber + SecondNumber + ThirdNumber;
                    TestProduct = FirstNumber * SecondNumber * ThirdNumber;
                    
                    if(TestSum == SumToSolve && TestProduct == ProductToSolve)
                    {
                        std::cout << FirstNumber << " " << SecondNumber << " " << ThirdNumber << std::endl;
                    }              
                }
            }
        }

        std::cout << "\nSolve another?  y/n?\n";
        std::cin >> YesNo;
        if(YesNo == 'y')
        {
           ContinuePlay = true;
        }
        else
        {
            ContinuePlay = false;
        }
    }   //while loop ends here
}

Thanks for reading!

-WillC

1 Like

Privacy & Terms