Triple X - The Math Exam

Just finished mine~
Switch statements are not included in the course but happy to be able to use it on the storyline.

#include <iostream>
#include <stdlib.h>
#include <ctime>
#include <conio.h>

void Dialogue (int Difficulty, int Try) // Most Dialogues are handled here
{
    switch (Try)
    {
    case 1:
        std::cout << "\n(HEEEEEEEEYYY, I'm serious, if you failed this one, you're doomed -_-)";
        break;
    case 2:
        std::cout << "\n(Hey, only 2 tries left, just 2 more and you're dead) ";
        break;
    case 3:
        switch (Difficulty)
        {
        case 1:
            std:: cout << std::endl;
            break;
        case 2:
            std::cout << "\n(You didn't expect this to have levels, don't you?)";
            break;
        case 3:
            std::cout << "\n            (YEEEEY Levels, I love levels)";
            break;
        case 4:
            std::cout << "\n(Ohhhhh~ You're good. Is your brain working hard? or hardly working? HAHAHAHAHA)";
            break;
        case 5:
            std::cout << "\n(Hmmm... didn't expect you to come this far... I underestimated you.)";
            break;
        }
        break;
    }

}

void PrintIntroduction (int Difficulty, int Try)
{
    // Printing the intro for the game
    system("cls");
    if (Difficulty==1 && Try == 3)
    {
        std::cout << "\nooooooooooooo           o8o             oooo                 ooooooo  ooooo ";
        std::cout << "\n8'   888   `8           `\"'             `888                  `8888    d8' ";
        std::cout << "\n     888      oooo d8b oooo  oo.ooooo.   888   .ooooo.          Y888..8P    ";
        std::cout << "\n     888      `888""8P   `888   888' `88b  888  d88' `88b          `8888'   ";
        std::cout << "\n     888       888      888   888   888  888  888ooo888         .8PY888.    ";
        std::cout << "\n     888       888      888   888   888  888  888    .o        d8'  `888b   ";
        std::cout << "\n    o888o     d888b    o888o  888bod8P' o888o `Y8bod8P'      o888o  o88888o ";
        std::cout << "\n                              888                                           ";
        std::cout << "\n                             o888o                                          ";
        std::cout << "\n                                                                            ";     "                                                                                                                                        \n";
        std::cout << "\nYou are a student breaking into your math teacher's office..."; 
        std::cout << "\nYou are to steal the exam because this is your last chance to pass..."; 
        std::cout << "\n\n                Press Enter to continue...\n";
        getch();
        system ("cls");
        _sleep(500);
        std::cout << "\nYou have found your teacher's computer.";
        _sleep(2500);
        std::cout << "\nYou have found the files that you needed.";
        _sleep(2000);
        std::cout << "\nYou clicked on it.";
        _sleep(1500);
        system ("cls"); 
       std::cout << "\n\n                [Intrudert Alert]\n";
        _sleep(1500);
        system ("cls");
        std::cout << "\nDamn, SECURITY!";
        _sleep(1500);
        system ("cls");
    }
    
    if (Difficulty != 1)
    {
        std::cout << "\n                   Level " << Difficulty;
        Dialogue (Difficulty, Try);
        _sleep(1500);
    }

    if (Try != 3)
    {
        std::cout << "\n\n                Tries left: " << Try;
        _sleep(1500);
    }
}

bool PlayGame (int Difficulty, int Try)
{
    PrintIntroduction(Difficulty, Try);
    // Declare 3 number code
    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 to the terminal
    std::cout << std::endl; 
    std::cout << "\n\"Riddle Riddle Riddle...\", the computer starts to say."; 
    std::cout << "\n\"Three numbers for you to handle.\""; 
    std::cout << "\n\"The codes add-up to " << CodeSum << "\""; 
    std::cout << "\n\"Multiplied to give " << CodeProduct << "\""; 
    std::cout << "\n\"What numbers would it be?\"";  
    _sleep(2000);
    
    if (Difficulty == 1)
    {
        std::cout << "\n\nThe computer waits for your response.";
        _sleep(1500);
        std::cout << "\n\nHint: Enter 1 1 1";
        _sleep(1500);
    }

    //Store Player Guess
    std::cout << std::endl;
    std::cout << "\nEnter the Code: ";
    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)
    {
        //_sleep(500);
        std::cout << "\n         Heeey, right choice~";
        _sleep(1500);
        std::cout << "\n\n            Bummer~ ";
        _sleep(800);
        return true;
    }
    else
    {
        if (Try >= 2)
        {
            //_sleep(500);
            std::cout << "\n\"You suck at these, don't you?\", the computer responded with dismay...";
            _sleep(1000);
            std::cout << "\n                         Try again.";
            _sleep(1500);
        }
        return false;
    }
}

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

    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;
    int Tries = 3;

    while (LevelDifficulty <= MaxDifficulty) // Loop the game until complete
    {
        bool bLevelComplete = PlayGame (LevelDifficulty,Tries);
        std::cin.clear();  // Clears any error
        std::cin.ignore(); // Discards the buffer

        if (bLevelComplete == false)
        {
            --Tries;
        }
        else if (bLevelComplete)
        {
            ++LevelDifficulty;
            Tries = 3;
        }
        
        if (Tries==0)
        {
            system("cls");
            std::cout << "\n         You have your 3 tries already.";
            _sleep(1000);
            std::cout << "\n   And the computer exploded at your face!\n\n";
            _sleep(1000);
            std::cout << "\n                 GAME OVER!\n\n";
            return 0;
        }
        
    } 
    
    system("cls");
    std::cout << "\n               Congratulations~\n";
    _sleep(1000);
    std::cout << "\n         You beat the hell out of me.\n";
    _sleep(1000);
    std::cout << "\n                  Nooooooow...\n";
    _sleep(2000);
    std::cout << "\nHere's the stash of P*rn that you wanted *Smile*\n";
    _sleep(2000);
    std::cout << "\n       OHH, this isn't what you're after?\n";
    _sleep(1500);
    std::cout << "\n          Geez, you should have told me.\n";
    _sleep(1500);
    std::cout << "\n       I could've just handed you the file. -_-\n";
    _sleep(3000);

    std::cout << "\n\n           Thanks for playing!\n\n";

    return 0;
}

Happy to be part of this community :relaxed:

Privacy & Terms