My TripleX Project

Here is my TripleX Console game. I’ve made some modifications.

  • Put in pauses to the gameplay so the user would manually advance in places - especially the end (If you run the compiled exe outside of the terminal it closes the window without giving the user time to read the “victory” message).

  • I added some different flavor to the project.

  • ASCII art took some formatting for breaking out \ characters

  • I separated the game intro text from the “next level” text

  • I removed the first level because it was always 1 1 1. so I have it duplicate level 2 for both level 1 & 2

// windows compile cl TripleX.cpp /EHsc
// Mac & Linux compile g++ TripleX.Cpp

#include <iostream>
#include <ctime>

void PrintIntroduction()
{
   // Intro story for the game
    std::cout << "\n\n        ,     \\    /      ,        \n";
    std::cout << "       / \\    )\\__/(     / \\       \n";
    std::cout << "      /   \\  (_\\  /_)   /   \\      \n";
    std::cout << " ____/_____\\__\\@  @/___/_____\\____ \n";
    std::cout << "|             |\\../|              |\n";
    std::cout << "|              \\VV/               |\n";
    std::cout << "|     Portal To The Far Realm     |\n";
    std::cout << "|_________________________________|\n";
    std::cout << " |    /\\ /      \\        \\ /\\    | \n";
    std::cout << " |  /   V        ))       V   \\  | \n";
    std::cout << " |/     `       //        '     \\| \n";
    std::cout << " `              V                '\n\n";
    std::cout << "You are an adventurer on a quest to the far realms.\n";
    std::cout << "Your quest has led you to the altar of the portal.\n";
    std::cout << "Three altars are before you each with a golden bowl on them.\n";
    std::cout << "Piles of magical gems cover the ground.\n\n";
}
void ChallengeText(int Difficulty)
{
    std::cout << "\nA voice speaks in a booming tones:\n\n";
    std::cout << "\"Place the correct number of gems in each vessel.\"\n";
    std::cout << "\"I will test you " << 6 - Difficulty << " more times to see if you are worthy.\"\n";

}
int PlayGame(int Difficulty)
{
    ChallengeText(Difficulty);

    // I don't like starting every game with 1-1-1 so I'm going to raise the first level difficulty
    if (Difficulty == 1)
    {
        ++Difficulty;
    }
    
    // Used "Bowl" instead of "Code" to match story "flavor"
    const int BowlA = rand() % Difficulty + Difficulty;
    const int BowlB = rand() % Difficulty + Difficulty;
    const int BowlC = rand() % Difficulty + Difficulty;

    // Bowl Math
    const int BowlSum = BowlA + BowlB + BowlC; 
    const int BowlProduct = BowlA * BowlB * BowlC;

    std::cout << "\n+ Place some number of gems in each vessel.\n\n";
    std::cout << "+ Place a total of " << BowlSum << " gems into the vessels.\n\n";
    std::cout << "+The number of gems in each vessel should \nmultiply together to give you " << BowlProduct << "\n\n";
    std::cout << "(enter three numbers separated by spaces)\n\n";

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

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC; 
    std::string Continue = "n";

    if (GuessSum == BowlSum && GuessProduct == BowlProduct)
    {
        std::cout << "You may be worthy...\n\nContinue? y/n\n";
        std::cin >> Continue;
        if (Continue == "y" || Continue == "Y")
        {
            return 1;
        }
        else
        {
            std::cout << "\nThen you are not worthy";
            return 0;

        }
        
    }
    else
    {
        std::cout << "\"You are not worthy.\"\nWould you like to try again? (y/n)";
        std::cin >> Continue;
        if (Continue == "y" || Continue == "Y")
        {
            return 2;
        }
        else
        {
            std::cout << "\n\"Then you truly are not worthy\"";
            return 0;

        }
        return false;
    }
}

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

    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;

    while (LevelDifficulty <= MaxDifficulty) // Loop until all levels are completed
    {
        int bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear(); //clear input errors 
        std::cin.ignore(); //Discard cin Buffer

        if (bLevelComplete == 1)
        {
            ++LevelDifficulty;
        }
        else if (bLevelComplete == 0)
        {
            LevelDifficulty = 100;
        }
        
    }
    
    std::string End = "n";
    if (LevelDifficulty == 6)
    {
        std::cout << "\n\n\"Hmm...\" The voice appears to be pondering.\n\"You truly are worthy!\"\nA portal opens beside the pillars.\n\"Be careful in the far realms - there are terrible dangers.\"\n\"Here, You will need this.\"\nIn front of the portal appears a staff glowing with magic power.\nYou take it and venture through the portal\nto the far realms...\nto more adventures.\n\n The End\n\n(End program? y/n)";

        std::cin >> End;
    }
    else
    {
        std::cout << "\n\"You waste my time\"\nThe altars vanish\n\nYou stand alone in an empty field\nThe End\n\n(End program? y/n)";
        std::cin >> End;
    }
    while (End != "y" && End != "Y")
    {
        std::cout << "(End program? y/n)";
        std::cin >> End;
    }
    return 0;
}
1 Like

Nice work!

In my TripleX Project, once the user completed the game, I wanted to clear the terminal and just display a message that they had beat the game.

I looked around online for the simplest way to clear a terminal screen. This code actually just forces the terminal to carriage return all the way to the bottom. The user can still scroll up to see the previous feedback if they want to.
image

I also tried “system(“clear”);” but got this error: “‘clear’ is not recognized as an internal or external command, operable program or batch file.”.

Privacy & Terms