TripleX Challenge: Lives, Alternate Responses for Lives & Levels, & Dinosaurs

Here is my TripleX game from the Unreal class. The premise is that you are a mad scientist creating Dinosaurs by combining the correct sequences of DNA.

I added lives by incorporating Tries (I learned this from @michaelofearth Triple X Game - Modified with 4 lives) but I modified what he did slightly because I wanted different responses with different ASCII graphics for each failed guess.

There are also different responses for each level if the player guesses correctly. Each response to the player’s guess has its own individual ASCII graphic.

All ASCII art came from https://www.asciiart.eu/.

This is my first ever attempt at coding so if something could have been done more easily, please let me know! I was totally improvising and somehow, after much trial and error, it worked!

#include <iostream>
#include <ctime>

void PrintIntroduction()
{
    std::cout << std::endl;
    std::cout << "o---O                                                                                                    o---O\n";
    std::cout << "O---o                                                                                                    O---o\n";
    std::cout << " O-o   @@@@@@@@@@@  @@@@@@@@@    @@@@@@@@@@@  @@@@@@@@@    @@@          @@@@@@@@@@@      @@          @@   O-o \n";    
    std::cout << "  O        @@@      @@@     @@@      @@@      @@@     @@@  @@@          @@@                @@      @@      O  \n";
    std::cout << " o-O       @@@      @@@     @@@      @@@      @@@     @@@  @@@          @@@                  @@  @@       o-O \n";
    std::cout << "o---O      @@@      @@@@@@@@         @@@      @@@@@@@@@    @@@          @@@@@@@@@@@            @@        o---O\n";
    std::cout << "O---o      @@@      @@@   @@@        @@@      @@@          @@@          @@@                  @@  @@      O---o\n";
    std::cout << " O-o       @@@      @@@    @@@       @@@      @@@          @@@          @@@                @@      @@     O-o \n";
    std::cout << "  O        @@@      @@@     @@@  @@@@@@@@@@@  @@@          @@@@@@@@@@@  @@@@@@@@@@@      @@          @@    O  \n";
    std::cout << " o-O                                                                                                      o-O \n";
    std::cout << "o---O                                                                                                    o---O\n";
    std::cout << "-----------------------------------------------------------------------------------------------------------------\n\n";
    std::cout << "                      You are Dr. X, a mad scientist experimenting with dinosaur DNA.\n";
    std::cout << "    A dinosaur's DNA sequence is made up of a specific 3-number combination that you must calculate using \n";
    std::cout << "                        complex mathematics. The wrong sequence could be deadly...\n";
}

void PrintLevel(int Difficulty)
{
    // Print intro message to terminal
    std::cout << "\n-----------------------------------------------------------------------------------------------------------------";
    std::cout << "\n\nCreate a Level " << Difficulty;
    std::cout << " Dinosaur by discovering the correct DNA sequence.\n\n";
}

bool PlayGame(int Difficulty)
{
    PrintLevel(Difficulty);
    
    //Declare 3 number code the player will guess
    const int CodeA = rand() % Difficulty + Difficulty; 
    const int CodeB = rand() % Difficulty + Difficulty;  
    const int CodeC = rand() % Difficulty + Difficulty;

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

    //Print sum and product hints to terminal
    std::cout << "There are three numbers in the DNA sequence.";
    std::cout << "\n + The numbers add up to: " << CodeSum;
    std::cout << "\n x And the numbers multiply to equal: " << CodeProduct;
    std::cout << "\n\nUsing numbers 1-9, what is the DNA sequence? Enter the numbers, putting a space between each ";
    std::cout << "\nnumber to separate them. Press ENTER when you have completed the DNA sequence.\n";

    //Declare variables for storing player's guess
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;
    std::cout << std::endl;

    //Declare sum & product of the player's guess
    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    //Check if Player's Guess is Correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct && Difficulty == 1)
    { 
        std::cout << "-----------------------------------------------------------------------------------------------------------------\n";
        std::cout << "\nWell done, Dr. X!";
        std::cout << "\nYou've successfully made a Triceratops!";
        std::cout << R"(
                                                                . - ~ ~ ~ - .
                                              ..     _      .-~               ~-.
                                             //|     \ `..~                      `.
                                            || |      }  }              /       \  \
                                        (\   \\ \~^..'                 |         }  \
                                         \`.-~  o      /       }       |        /    \
                                         (__          |       /        |       /      `.
                                          `- - ~ ~ -._|      /_ - ~ ~ ^|      /- _      `.
                                                      |     /          |     /     ~-.     ~- _
                                                      |_____|          |_____|         ~ - . _ _~_-_)" << std::endl;
        return true;
    }

    if (GuessSum == CodeSum && GuessProduct == CodeProduct && Difficulty == 2)
    {
        std::cout << "-----------------------------------------------------------------------------------------------------------------\n";
        std::cout << "\nWell done, Dr. X!";
        std::cout << "\nYou've successfully made an Stegosaurus!";
        std::cout << R"(
                                                             .       .
                                                            / `.   .' \
                                                    .---.  <    > <    >  .---.
                                                    |    \  \ - ~ ~ - /  /    |
                                                     ~-..-~             ~-..-~
                                                 \~~~\.'                    `./~~~/
                                       .-~~^-.    \__/                        \__/
                                     .'  O    \     /               /       \  \
                                    (_____,    `._.'               |         }  \/~~~/
                                     `----.          /       }     |        /    \__/
                                           `-.      |       /      |       /      `. ,~~|
                                               ~-.__|      /_ - ~ ^|      /- _      `..-'   f: f:
                                                    |     /        |     /     ~-.     `-. _||_||_
                                                    |_____|        |_____|         ~ - . _ _ _ _ _>)" <<std::endl;
        return true;
    }

    if (GuessSum == CodeSum && GuessProduct == CodeProduct && Difficulty == 3)
    {
        std::cout << "-----------------------------------------------------------------------------------------------------------------\n";
        std::cout << "\nWell done, Dr. X!";
        std::cout << "\nYou've successfully made an Ankylosaurus!"; 
        std::cout << R"(
                                                     /~~~~~~~~~~~~\_
                                 _+=+_             _[~  /~~~~~~~~~~~~\_
                                {""|""}         [~~~    [~   /~~~~~~~~~\_
                                 """:-'~[~[~"~[~  ((++     [~  _/~~~~~~~~\_
                                      '=_   [    ,==, ((++    [    /~~~~~~~\-~~~-.
                                         ~-_ _=+-(   )/   ((++  .~~~.[~~~~(  {@} \`.
                                                 /   }\ /     (     }     (   .   ''}
                                                (  .+   \ /  //     )    / .,  """"/
                                                \\  \     \ (   .+~~\_  /.= /'""""
                                                <"_V_">      \\  \    ~~~~~~\\  \
                                                              \\  \          \\  \
                                                              <"_V_">        <"_V_"> )" << std::endl;
        return true;       
    }

    if (GuessSum == CodeSum && GuessProduct == CodeProduct && Difficulty == 4)
    {
        std::cout << "-----------------------------------------------------------------------------------------------------------------\n";
        std::cout << "\nWell done, Dr. X!";
        std::cout << "\nYou've successfully made a Velociraptor!";
        std::cout << R"(
                                                                         ___._
                                                                       .'  <0>'-.._
                                                                      /  /.--.____")
                                                                     |   \   __.-'~
                                                                     |  :  -'/
                                                                    /:.  :.-'
                    __________                                     | : '. |
                    '--.____  '--------.______       _.----.-----./      :/
                            '--.__            `'----/       '-.      __ :/
                                  '-.___           :           \   .'  )/
                                        '---._           _.-'   ] /  _/
                                             '-._      _/     _/ / _/
                                                 \_ .-'____.-'__< |  \___
                                                   <_______.\    \_\_---.7
                                                  |   /'=r_.-'     _\\ =/
                                              .--'   /            ._/'>
                                            .'   _.-'
                                           / .--'
                                          /,/
                                          |/`)
                                          'c=,)" << std::endl;
        return true;        
    }

    if (GuessSum == CodeSum && GuessProduct == CodeProduct && Difficulty == 5)
    {
        std::cout << "-----------------------------------------------------------------------------------------------------------------\n";
        std::cout << "\nCongratulations, Dr. X! You are a MASTER at combining Dinosaur DNA.";
        std::cout << "\nYou've successfully made a Tyrannosaurus rex!";
        std::cout << R"(
                                                                              ____
                                 ___                                      .-~. /_"-._
                                `-._~-.                                  / /_ "~o\  :Y
                                      \  \                                / : \~x.  ` ')
                                      ]  Y                              /  |  Y< ~-.__j
                                     /   !                        _.--~T : l  l<  /.-~
                                    /   /                 ____.--~ .   ` l /~\ \<|Y
                                   /   /             .-~~"        /| .    ',-~\ \L|    < RRRAAAWWWRRRRRR
                                  /   /             /     .^   \ Y~Y \.^>/l_   "--'
                                 /   Y           .-"(  .  l__  j_j l_/ /~_.-~    .
                                Y    l          /    \  )    ~~~." / `/"~ / \.__/l_
                                |     \     _.-"      ~-{__     l  :  l._Z~-.___.--~
                                |      ~---~           /   ~~"---\_  ' __[>
                                l  .                _.^   ___     _>-y~
                                 \  \     .      .-~   .-~   ~>--"  /
                                  \  ~---"            /     ./  _.-'
                                   "-.,_____.,_  _.--~\     _.-~
                                           ~~     (   _}       
                                                      `. ~(
                                                        )  \
                                                  /,`--'~\--'~\
                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)" << std::endl;
        return true;  
    }
    else
    {
        return false;
    } 
}

int main() 
{
    PrintIntroduction();

    srand(time(NULL)); //creats a new random sequence based on time of day
    
    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;
    int Tries = 2;

    while (LevelDifficulty <= MaxDifficulty) //Loop the game until all levels are completed
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear(); //Clears any errors
        std::cin.ignore(); //Discards bad characters in input buffer
    
        //Return values for getting an incorrect answer and losing tries
        if (bLevelComplete == false && Tries == 0)  
        {
            std::cout << "-----------------------------------------------------------------------------------------------------------------\n";
            std::cout << "\nOh no, Dr. X! You entered the wrong DNA sequence and created an aligator!";
            std::cout << "\nThe aligator attacked you and you died, never knowing what dinosaurs you could have created.\n\n";
            std::cout << R"(
                                                 _  _
                                            _ _ (0)(0)-._  _.-'^^'^^'^^'^^'^^'--.
                 YOU LOSE.                 (.(.)----'`        ^^'                /^   ^^-._
                 GAME OVER.                (    `                 \             |    _    ^^-._
                                            VvvvvvvVv~~`__,/.._>  /:/:/:/:/:/:/:/\  (_..,______^^-.
                                             `^^^^^^^^`/  /   /  /`^^^^^^^^^>^^>^`>  >        _`)  )
                                                      (((`   (((`          (((`  (((`        `'--'^)" << std::endl;
            std::cout << std::endl;
            return 0;
        }

        if (bLevelComplete == false && Tries == 1)
        {
            std::cout << "-----------------------------------------------------------------------------------------------------------------\n";
            std::cout << "\nCareful, Dr.X. You entered the wrong DNA sequence and created a scorpion!";
            std::cout << "\nHe attacked you but you successfully recovered.";
            std::cout << R"(
                                                        ___    ___
                                                       ( _<    >_ )
                                                       //        \\
                                                       \\___..___//
                                                        `-(    )-'
                                                          _|__|_
                                                         /_|__|_\
                                                         /_|__|_\
                                                         /_\__/_\
                                                          \ || /  _)
                                                            ||   ( )
                                                            \\___//
                                                             `---')";
            std::cout << "\nYou have " << Tries;
            std::cout << " try left.\n";
            --Tries;
        }

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }

        if (bLevelComplete == false && Tries >= 1)
        {
            std::cout << "-----------------------------------------------------------------------------------------------------------------\n";
            std::cout << "\nCareful, Dr.X. You entered the wrong DNA sequence and created a frog!";
            std::cout << "\nThis wasn't exactly what you were going for.";
            std::cout << R"(
                                                     _   _
                                                    (.)_(.)
                                                 _ (   _   ) _
                                                / \/`-----'\/ \
                                              __\ ( (     ) ) /__
                                              )   /\ \._./ /\   (
                                               )_/ /|\   /|\ \_()";
            std::cout << "\nYou have " << Tries;
            std::cout << " tries left.\n";
            --Tries;
        }

        if (bLevelComplete && LevelDifficulty <= MaxDifficulty)
        {
            std::cout << "Keep going! You're not done yet.....\n";
        }
    }

    std::cout << "\nYour T-Rex ate all the other Dinosaurs but what else would you expect from the KING OF ALL DINOSAURS?";
    std::cout << "\nYou survived the T-Rex and are now being considered for the Nobel Prize.";
    std::cout << "\n\n                                               YOU WIN. THE END\n\n";
    return 0;
}

ASCII Art is nice, but did you create it? Welll, that kind of art looks like website piece. Well, but nice!

1 Like

@kaushal_vesta
Thank you! I did not create it. I got it from this ASCII art website: https://www.asciiart.eu/.
I just inserted it into the game.

Ok! But I suggest you to create! Well, I have to appreciate you for the patience you had for writing:

std::cout << “”;

many times!

1 Like

Privacy & Terms