TripleX Game!

#include <iostream>
#include <ctime>

void PrintIntroduction(int Difficulty)
{
    std::cout << "*You have entered the vault*\n";
    std::cout << "That was a close one.\n";
    std::cout << "Now all I need is to pick the safe!\n\n";
    std::cout << "You are on safe " << Difficulty << std::endl;
}

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

    // defining variables

    int const CodeA = rand() % Difficulty + Difficulty;
    int const CodeB = rand() % Difficulty + Difficulty;
    int const CodeC = rand() % Difficulty + Difficulty;

    int const CodeSum = CodeA + CodeB + CodeC;
    int const CodeProduct = CodeA * CodeB * CodeC;


    // print defined variables

    std::cout << "- There are 3 numbers in the code to the safe";
    std::cout << "\n- The codes add up to " << CodeSum;
    std::cout << "\n- The codes multiply to get " << CodeProduct << std::endl << std::endl;


    // store player guess

    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;


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


    // logic system (player answer check)

    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\nYou cracked the safe! Wait what?! THERES ANOTHER SAFE IN THE SAFE?!\n\n";
        return true;
    }
    else
    {
        std::cout << "\nOh no! The safe self destructed due to a wrong combination!\n\n";
        return false;
    }
}


int main ()
{
    srand(time(NULL));

    int LevelDifficulty = 1;
    int const MaxDifficulty = 6;

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

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }
    std::cout << "That was the last safe, look what's inside!\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";

    return 0;
}

/*                                         
                 .,,,,,,,,    
             ,,.,....,,,,,(,* 
         ..,..,,(,,,,,.,,,,,, 
    ...,*....,,,,,.,,,,,,,,,**
  .  ,,,,,,,,,.,,,,,,,,,,**   
 ...... @,.,,,,,,,,,,,*       
 ........*,,,,,,,,*           
    .....*,,,,*               
        .*,                                                                                      
*/

Privacy & Terms