Final Result of TripleX Game

Here is the code:

#include <iostream>
#include <ctime>

void PrintIntroduction()
{
    // Introduce the scene
    std::cout << R"(

                    ______
                   / _  - \
                  |  _  _  |
                 |    ___   |
         \/__     |________|     __ \/
          |O_ \   /         \   / _O| 
            \  \/  /       \  \/  /
             \    /         \    /
               _ __|_     _|__ _
            /    _____     _____   \
              -- ___ | || |___ --
                     \_||_/

                          
    )" << '\n';
    std::cout << "You enter the mountain temple. There, seated on a pile of cushions in front of the cave entrance, is a old and withered monk.";
    std::cout << "\n";
    std::cout << "'Ah!' He says, 'Our new janitor! Before you begin your work, I would like you to solve a puzzle for me...'";
    std::cout << "\n";
}

void PrintLevelIntro(int Difficulty)
{
    std::cout << "\n\nLevel " << Difficulty << "\n";
    std::cout << "\nIt looks as though the monk is arranging something...\n";
}

bool PlayGame(int Difficulty)
{

    PrintLevelIntro(Difficulty);

    // Set rocks
    const int Stone1 = rand() % Difficulty + Difficulty;
    const int Stone2 = rand() % Difficulty + Difficulty;
    const int Stone3 = rand() % Difficulty + Difficulty;



    const int StoneSum = Stone1 + Stone2 + Stone3;
    const int StoneProduct = Stone1 * Stone2 * Stone3;


    // Print clues
    std::cout << "There are three stones on the floor, each with a hidden number." << "\n";
    std::cout << "The sum of the stones' numbers are " << StoneSum << "\n";
    std::cout << "The product of the stones' numbers are " << StoneProduct << "\n";

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

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


    // Check if the player guess is correct
    if (GuessSum == StoneSum && GuessProduct == StoneProduct)
    {
        std::cout << "You are correct! The monk is very impressed with your wisdom.";
        return true;
    }
    else
    {
        std::cout << "It looks as though the monk has stumped you! Try again!";
        return false;
    }
}



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

    int LevelDifficulty = 1;
    const int MaxLevel = 5;

    PrintIntroduction();

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

        if (bLevelComplete) 
        {
            ++LevelDifficulty;
        }

    }
    
    std::cout << "\n\nAmazing! You have solved all of the monk's puzzles! For this, the monk lets you pass so you can wipe the floors in the other room.";

    return 0;
}
1 Like

Incredible code

Privacy & Terms