My Complete TripleX Game

#include<iostream>
#include<ctime>
void PrintIntroduction()
{

    // Print welcome messages to the terminal
       
                                                                                                                      
std::cout << "\n\nTTTTTTTTTTTTTTTTTTTTTTT                     iiii                     lllllll                   XXXXXXX       XXXXXXX\n";
std::cout << "T:::::::::::::::::::::T                    i::::i                    l:::::l                   X:::::X       X:::::X\n";
std::cout << "T:::::::::::::::::::::T                     iiii                     l:::::l                   X:::::X       X:::::X\n";
std::cout << "T:::::TT:::::::TT:::::T                                              l:::::l                   X::::::X     X::::::X\n";
std::cout << "TTTTTT  T:::::T  TTTTTTrrrrr   rrrrrrrrr  iiiiiiippppp   ppppppppp    l::::l     eeeeeeeeeeee  XXX:::::X   X:::::XXX\n";
std::cout << "        T:::::T        r::::rrr:::::::::r i:::::ip::::ppp:::::::::p   l::::l   ee::::::::::::ee   X:::::X X:::::X   \n";
std::cout << "        T:::::T        r:::::::::::::::::r i::::ip:::::::::::::::::p  l::::l  e::::::eeeee:::::ee  X:::::X:::::X    \n";
std::cout << "        T:::::T        rr::::::rrrrr::::::ri::::ipp::::::ppppp::::::p l::::l e::::::e     e:::::e   X:::::::::X     \n";
std::cout << "       T:::::T         r:::::r     r:::::ri::::i p:::::p     p:::::p l::::l e:::::::eeeee::::::e   X:::::::::X      \n";
std::cout << "        T:::::T         r:::::r     rrrrrrri::::i p:::::p     p:::::p l::::l e:::::::::::::::::e   X:::::X:::::X    \n";
std::cout << "        T:::::T         r:::::r            i::::i p:::::p     p:::::p l::::l e::::::eeeeeeeeeee   X:::::X X:::::X   \n";
std::cout << "        T:::::T         r:::::r            i::::i p:::::p    p::::::p l::::l e:::::::e         XXX:::::X   X:::::XXX\n";
std::cout << "      TT:::::::TT       r:::::r           i::::::ip:::::ppppp:::::::pl::::::le::::::::e        X::::::X     X::::::X\n";
std::cout << "      T:::::::::T       r:::::r           i::::::ip::::::::::::::::p l::::::l e::::::::eeeeeeeeX:::::X       X:::::X\n";
std::cout << "      T:::::::::T       r:::::r           i::::::ip::::::::::::::pp  l::::::l  ee:::::::::::::eX:::::X       X:::::X\n";
std::cout << "      TTTTTTTTTTT       rrrrrrr           iiiiiiiip::::::pppppppp    llllllll    eeeeeeeeeeeeeeXXXXXXX       XXXXXXX\n";
std::cout << "                                                  p:::::p                                                           \n";
std::cout << "                                                  p:::::p                                                           \n";
std::cout << "                                                 p:::::::p                                                          \n";
std::cout << "                                                 p:::::::p                                                          \n";
std::cout << "                                                 p:::::::p                                                          \n";
std::cout << "                                                ppppppppp                                                           \n";
                                                                                                                    
    




    std::cout << "You are a Special Agent breaking into LAUNCH CONTROL ROOM to abort the missile launch. \n";
    std::cout << "You break into the room but find no one\n";
    std::cout << "You see a countdown on a huge screen '2 minutes to launch'\n";

    std::cout <<"     |.------------.| \n";
    std::cout <<"     || countdouwn || \n";
    std::cout <<"     ||            || \n";
    std::cout <<"     ||    2:00    || \n";
    std::cout <<" __  ||            || \n";
    std::cout <<"|==| ||____________|| \n";
    std::cout <<"|88| |[##]o O[Abort]| \n";
    std::cout <<"|88| |==Launch=======| \n";
    std::cout <<"`--' """""""""""""""" \n";






    std::cout << "You rush towards the control panel and press the abort key\n";
   

}

  bool PlayGame(int Difficulty)
 {
    
    std::cout << "\nLevel " << Difficulty;
    std::cout << "\nEnter the correct abort codes to continue...\n\n";

    // Declare 3 numbers to the terminal

    const int CodeA = rand() % Difficulty + Difficulty;
    const int CodeB = rand() % Difficulty + Difficulty;
    const int CodeC = rand() % Difficulty + Difficulty;
 
    // Print CodeSum and CodeProduct to the terminal
    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    std::cout <<std::endl;
    std::cout << "+ 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 <<std::endl;

    int GuessA, GuessB, GuessC;
    
    // Store player Guess 
    std::cin >> GuessA >> GuessB >> GuessC;
    
    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProoduct = GuessA * GuessB * GuessC;
    
    if (GuessSum == CodeSum && GuessProoduct == CodeProduct)
    {
       std::cout << "\n**Well Done!! You entered the correct code**.\n";
       return true;
    }
     else
    {
        std::cout << "\n**You entered the wrong code.**\n";
        std::cout << "\n**Try again!**\n";
        return false;
    }

}
int main()
{ 
   PrintIntroduction();
   srand(time(NULL)); // creates new random sequence based on time of day
   
    int LevelDificulty = 1;
    const int MaxDifficulty = 5;

    while (LevelDificulty <= MaxDifficulty) //Loop game until all levels are completed
   {
       bool bLevelComplete = PlayGame(LevelDificulty);
       std::cin.clear();//clears any errors
       std::cin.ignore();//Discards the buffer

       if (bLevelComplete)
       {
        
        ++LevelDificulty;

       }
       
   }
    
    std::cout << "\n^^Great work Agent 47! You succesfully aborted the launch^^";
    
    return 0;

}  
3 Likes

Well done! :clap:

1 Like

Congratz :smiley:

1 Like

Privacy & Terms