TripleX Winter Disaster Story Finished

First ever work, course explanations were great. Cant wait to start next chapter.

Code:

#include <iostream>
#include <ctime>

void EndGame()
{
    std::cout << "\n\"V^lid cod& combination: t*rmin@tion initi(liz&d\"\n";
    std::cout << "\"St%nd by...\"\n";
    std::cout << "\"1@...\"\n";
    std::cout << "\"9...\"\n";
    std::cout << "\"8...\"\n";
    std::cout << "\"7...\"\n";
    std::cout << "\"6...\"\n";
    std::cout << "\"5...\"\n";
    std::cout << "\"%...\"\n";
    std::cout << "\"3...\"\n";
    std::cout << "\"2...\"\n";
    std::cout << "\"1...\"\n";
    std::cout << "\n\"Sat^%lite terminat*d\"\n";
    std::cout << "\"Poj#ct files Ze&s terminated\"\n";
    std::cout << "\"Weath*r nominal cond^%ion state in 20.$# days\"\n";
    std::cout << "\"Le$d r&sear&her: V@k%4r K(ez#$v is notified\"\n";
    std::cout << "\"Sh%^tng down $ystem@\"\n";
    std::cout << "\nStunned by the digital text, you couldn't believe what you have just read.\n";
    std::cout << "While you were exiting the shelter, \n";
    std::cout << "strange shinning light, coming from outside the door, struck you in the eye.\n";
    std::cout << "You looked up and right there in space, a bright glare, exploded sattelite \n";
    std::cout << "illuminating Earth as if it was a sun.\n";
    std::cout << "You couldnt help but wonder, was this nightmare finally over?\n";
}

void PrintIntroduction()
{
    std::cout << "\n\n                                      *  .  *\n";
    std::cout << "          _       _                 . _\\/ \\/_ .\n";
    std::cout << "         (_)     | |                 \\  \\ /  /\n";
    std::cout << "__      ___ _ __ | |_ ___ _ __     -==>: X :<==-\n";
    std::cout << "\\ \\ /\\ / / | '_ \\| __/ _ \\ '__|      / _/ \\_ \\\n";
    std::cout << " \\ V  V /| | | | | ||  __/ |        '  /\\ /\\  '\n";   
    std::cout << "  \\_/\\_/ |_|_| |_|\\__\\___|_|          *  '  *\n";
    std::cout << "\nYou are sole survivor of a cold winter apocalypse.\n";
    std::cout << "Struggling through snow on an eternal dark, cloudy night, you stumbled upon a lost shelter covered with snow.\n";
    std::cout << "Shelter appeared to be empty with only one broken out underground passage.\n";
    std::cout << "Going deeper, you came across a room filled with rusty equipment, dusty consoles and screens.\n";
    std::cout << "One console seems to be flashing and showing a black screen with only text being...\n";
    std::cout << "\n\"Z$us pr*j%ct: failure\"\n";
    std::cout << "\"Atmokinesis mod#le in critical cond@tion\"\n";
    std::cout << "\"Ove^rid$ satel@)te systems: fa$lure\"\n";
    std::cout << "\"Critic*l state: t#rmina&ion required\"\n";
}

void PrintDifficulty(int Difficulty)
{
    std::cout << "\"Seq$6nce: " << Difficulty << "\"\n";
    std::cout << "\"E&ter t*e code: \"\n";
}

bool PlayGame(int Difficulty)
{
    PrintDifficulty(Difficulty);
    // Declare 3 number code
    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 sum and product to the terminal
    std::cout << "\n - There are 3 numbers in the code\n";
    std::cout << " - The code add-up to: " << CodeSum << "\n";
    std::cout << " - The code multiply to give: " << CodeProduct << "\n";

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

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

    // Check if the player's guess is correct
    if (GuessSum == CodeSum & GuessProduct == CodeProduct)
    {
        std::cout << "\n\"Seq*ence " << Difficulty << " c#$rect\"\n";
        return true;
    }
    else
    {
        std::cout << "\n\"Unv@^id code comb^nat$on: rest$%cting terminal *sage\"\n";
        std::cout << "\"Bl%cking cons^le\"\n";
        std::cout << "\"Cons#lt with lead res*&rcher: V@k%4r K(ez#$v\"\n";
        std::cout << "\nTired, defeated, lost, you walked outside, starring right into this dark abyss of a storm.\n";
        std::cout << "You felt on a shinning snow, without any hope, and couldn't help but wonder \n";
        std::cout << "would've this been it?\n";
        std::cout << "Could've you stopped this cold nightmare?\n";
        std::cout << "What was this project?\n";
        std::cout << "Who was this lead researcher and is he still alive?\n";
        std::cout << "As you were laying down on a snow covered by the storm shower, \n";
        std::cout << "unanswered questions rushed in your mind and left as quick, when your eyes finally...\n";
        std::cout << "Closed.\n\n";
        return false;
    }
}

int main()
{
    PrintIntroduction();
    srand(time(NULL)); // create new random sequence based on time of day

    int LevelDifficulty = 1;
    int const MaxDifficulty = 3;

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

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        else
        {
            return 0;
        }
    }

    EndGame();
    
    return 0;
}
2 Likes

I also love this section! You did an incredible job!

1 Like

Hey, thanks!

Privacy & Terms