Triple X - Taming rand()

I’m going to be honest, I didn’t even play it because I’m so bad at math! Overall though, this was a brilliant intro to C++ and I feel like I’ve genuinely achieved something.

#include <iostream> //import input output stream
#include <ctime> //import our computer's time

void PrintIntroduction(int Difficulty)
{
    std::cout << "\nYou broke into the Evil Wizard's Lair. Congratulations. Unfortunetly, it was a trap.\n";
    std::cout << "On the table in front of you, vials lay scattered with numbers written on them.\n";
    std::cout << "You find a note 'The room is filling with poison gas. ";
    std::cout << "You must mix three ingredients together ten times, mix, and then drink the final potion to stop the poison from killing you.\n";
    
    //must be a better way of doing this
    if (Difficulty == 1)
    {
        std::cout << "\nMix the " << Difficulty << "st Potion";
    }
    if(Difficulty == 2)
    {
        std::cout << "\nMix the " << Difficulty << "nd Potion";
    }
    if (Difficulty == 3)
    {
        std::cout << "\nMix the " << Difficulty << "rd Potion";
    }
    if (Difficulty != 1 && Difficulty != 2 && Difficulty !=3)
    {
        std::cout << "\nMix the " << Difficulty << "th Potion";
    }
}

void PrepareToDie()
{
    std::cout << "\n@@@@@@@   @@@@@@@   @@@@@@@@  @@@@@@@    @@@@@@   @@@@@@@   @@@@@@@@     @@@@@@@   @@@@@@      @@@@@@@   @@@  @@@@@@@@  \n";
    std::cout << "@@@@@@@@  @@@@@@@@  @@@@@@@@  @@@@@@@@  @@@@@@@@  @@@@@@@@  @@@@@@@@     @@@@@@@  @@@@@@@@     @@@@@@@@  @@@  @@@@@@@@  \n";
    std::cout << "@@!  @@@  @@!  @@@  @@!       @@!  @@@  @@!  @@@  @@!  @@@  @@!            @@!    @@!  @@@     @@!  @@@  @@!  @@!       \n";
    std::cout << "!@!  @!@  !@!  @!@  !@!       !@!  @!@  !@!  @!@  !@!  @!@  !@!            !@!    !@!  @!@     !@!  @!@  !@!  !@!       \n";
    std::cout << "@!@@!@!   @!@!!@!   @!!!:!    @!@@!@!   @!@!@!@!  @!@!!@!   @!!!:!         @!!    @!@  !@!     @!@  !@!  !!@  @!!!:!    \n";
    std::cout << "!!@!!!    !!@!@!    !!!!!:    !!@!!!    !!!@!!!!  !!@!@!    !!!!!:         !!!    !@!  !!!     !@!  !!!  !!!  !!!!!:    \n";
    std::cout << "!!:       !!: :!!   !!:       !!:       !!:  !!!  !!: :!!   !!:            !!:    !!:  !!!     !!:  !!!  !!:  !!:       \n";
    std::cout << ":!:       :!:  !:!  :!:       :!:       :!:  !:!  :!:  !:!  :!:            :!:    :!:  !:!     :!:  !:!  :!:  :!:       \n";
    std::cout << " ::       ::   :::  :: ::::   ::       ::   :::  ::   :::   :: ::::        ::    ::::: ::      :::: ::   ::   :: ::::  \n";
    std::cout << " :         :   : :  : :: ::    :         :   : :   :   : :  : :: ::         :      : :  :      :: :  :   :    : :: ::   \n";
    std::cout << "";
}
void YouWin()
{
    std::cout << "\nYou mix all the potions together.... down the hatch!\n";
    std::cout << "Congratulations, you live... for now..\n";
}

void YouDie()
{
    std::cout << "You ran out of potions to drink... you suffer a slow, painful death.\n";
}

//void function doesn't return any data type
bool PlayGame(int Difficulty)
{
    
    PrintIntroduction(Difficulty);

    //define vriables - declare 3 number code
    const int CodeA = rand() % Difficulty + Difficulty;
    const int CodeB = rand() % Difficulty + Difficulty;
    const int CodeC = rand() % Difficulty + Difficulty;

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

    //output calculations above
    std::cout << "\n+ 3 vials must be mixed together.";
    std::cout << "\n+ The 3 numbers on the vials add up to: " << CodeSum;
    std::cout << "\n+ The 3 numbers on the vials multiply together to: " << CodeProduct;
    std::cout << "\n\n- Mix the vials: \n";

    //prepare vars to store user input
    int GuessA, GuessB, GuessC;

    //receive user input
    std::cin >> GuessA >> GuessB >> GuessC;

    //calculate
    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;
    
    //check if player guess is correcty
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        //std::cout << "\nYou Survived!      ...For now.\n";
        std::cout << "Your potion mix fizzes and pops - it looks like you mixed this one right.\n";
        return true;
    }
    else
    {
        //std::cout << "\nYou Died a horrible, painful death!!\n";
        std::cout << "\nThis vial fizzes and splutters... that doesn't look right..\n";
        return false;
    }

}

//main is required to compile
int main()
{


    srand(time(null)); //creates new random sequence based on time of day.
    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;
    int MaxTries = 5;
    std::cout << PrepareToDie;
    while (LevelDifficulty <= MaxDifficulty && MaxTries > 0) //loop game until max difficilty complete
        {
            if (MaxTries !=0) //loops the game until all levels are complete or max tries runs out.
            {
                bool bLevelComplete = PlayGame(LevelDifficulty); //checks if level is complete
                std::cin.clear(); //clears any errors
                std::cin.ignore(); //discards the buffer  

                if (bLevelComplete)
                {
                    //increase the level difficulty
                    ++LevelDifficulty;
                    MaxTries = 5;
                }
                else
                {
                    --MaxTries;
                    std::cout << "\nCareful, you're running out of liquids.\n";
                    std::cout << "\nIt looks like you can mix " << MaxTries << " more potions with these vials.\n";
                }   
            }
    }

    if (MaxTries == 0)
    {
        YouDie();
    }
    else
    {
        YouWin();
    }
    return 0;
}```
2 Likes

My full game is 10 levels so it starts getting a lot harder at around lvl 6-7 and up.
I have also included 3 lifes and some monologue from Golum that got The Ring stuck in a box :stuck_out_tongue: . (I was to lazy to change most of the monologue so it is pretty standard)

#include <iostream>
#include <ctime>
void PrintIntroduction (int Difficulty, int CodeSum, int CodeProduct,int MaxLevel, int Lifes)
{
    int Level = Difficulty; 
  // Golum is has locked the ring in a box and the box gives 2 numbers and you have to figure out 3 numbers that make up the 2. 
    switch (Difficulty)
    {
    case (1):
        std::cout << "\n\nYou have started a game with Golum...\n You will DIE if you lose!\n\n";
        std::cout << "Golum approaches you \n\n ";
        std::cout << "Golum: \"Give me the correct numbers, I NNNEEEEEEDDD them to get My Presious\"\n";
        std::cout << "Golum: \"There is a number "<<Level <<"/"<< MaxLevel <<" on the box?? What\'s that for?\"";
        std::cout << "Golum: \"The box wants 3 numberss...\"\n\n";
        std::cout << "Golum: \"The box says the following: \"\n "; 
        std::cout << "Golum: The sum of the numbers are: " << CodeSum << " ,\n";
        std::cout << "Golum: and the product of the numbers are: " << CodeProduct <<".\nI NEED YOUR ANSWER!!! Hurry up!\n"; 
        std::cout << "Golum: \"You have " << Lifes << " chances left\"\n\n" ;      
        break;   
    case (2):
        std::cout << "\n Golum: \" It is STILL not OPEN\"\n";
        std::cout << "Golum: \"The first row of numbers changed it is now "<<Level <<"/"<< MaxLevel <<"... \n We you are going to have to help me"<<(MaxLevel-Level)<<" times HUMAN!\n (Golum seems agatated)\"\n";
        std::cout << "Golum: \"The sum of the new numbers we need are: " << CodeSum <<"\"\n";
        std::cout << "Golum: \"The next product is: "<< CodeProduct<<"\"\n";
        std::cout << "Golum: \"Don't fail me Human\"\n";
        std::cout << "Golum: \"You have " << Lifes << " chances left\"\n\n" ; 
        break;    
    case (3):
        std::cout << "\n Golum: \" It is STILL not OPEN\"\n";
        std::cout << "Golum: \"The first row of numbers changed it is now "<<Level <<"/"<< MaxLevel <<"...\"\n";
        std::cout << "Golum: \"The sum of the new numbers we need are: " << CodeSum <<"\"\n";
        std::cout << "Golum: \"The next product is: "<< CodeProduct<<"\"\n";
        std::cout << "Golum: \"Don't fail me Human\"\n";
        std::cout << "Golum: \"You have " << Lifes << " chances left\"\n\n";
        break;
    case (4):
        std::cout << "\n Golum: \" It is STILL not OPEN\"\n";
        std::cout << "Golum: \"The first row of numbers changed it is now "<<Level <<"/"<< MaxLevel <<"...\"\n";
        std::cout << "Golum: \"The sum of the new numbers we need are: " << CodeSum <<"\"\n";
        std::cout << "Golum: \"The next product is: "<< CodeProduct<<"\"\n\n";
        std::cout << "Golum: \"Don't fail me Human\"\n";
        std::cout << "Golum: \"You have " << Lifes << " chances left\"\n\n";
        break;
    case (5):
        std::cout << "\n Golum: \" It is STILL not OPEN\"\n";
        std::cout << "Golum: \"The first row of numbers changed it is now "<<Level <<"/"<< MaxLevel <<"...\"\n";
        std::cout << "Golum: \"The sum of the new numbers we need are: " << CodeSum <<"\"\n";
        std::cout << "Golum: \"The next product is: "<< CodeProduct<<"\"\n";
        std::cout << "Golum: \"Half way there\"\n";
        std::cout << "Golum: \"You have " << Lifes << " chances left\"\n\n";
        break;
    case (6):
        std::cout << "\n Golum: \" It is STILL not OPEN\"\n";
        std::cout << "Golum: \"The first row of numbers changed it is now "<<Level <<"/"<< MaxLevel <<"...\"\n";
        std::cout << "Golum: \"The sum of the new numbers we need are: " << CodeSum <<"\"\n";
        std::cout << "Golum: \"The next product is: "<< CodeProduct<<"\"\n";
        std::cout << "Golum: \"AAhhhh Let me have MY Presious you stupid box\"\n";
        std::cout << "Golum: \"You have " << Lifes << " chances left\"\n\n";
        break;
    case (7):
        std::cout << "\n Golum: \" It is STILL not OPEN\"\n";
        std::cout << "Golum: \"The first row of numbers changed it is now "<<Level <<"/"<< MaxLevel <<"...\"\n";
        std::cout << "Golum: \"The sum of the new numbers we need are: " << CodeSum <<"\"\n";
        std::cout << "Golum: \"The next product is: "<< CodeProduct<<"\"\n";
        std::cout << "Golum: \"3 to GO!\"\n";
        std::cout << "Golum: \"You have " << Lifes << " chances left\"\n\n";
        break;
    case 8:
        std::cout << "\n Golum: \" It is STILL not OPEN\"\n";
        std::cout << "Golum: \"The first row of numbers changed it is now "<<Level <<"/"<< MaxLevel <<"... \"\n";
        std::cout << "Golum: \"The sum of the new numbers we need are: " << CodeSum <<"\"\n";
        std::cout << "Golum: \"The next product is: "<< CodeProduct<<"\"\n";
        std::cout << "Golum: \"We have almost got it\"\n";
        std::cout << "Golum: \"You have " << Lifes << " chances left\"\n\n";
        break;
    case 9:
        std::cout << "\n Golum: \" It is STILL not OPEN\"\n";
        std::cout << "Golum: \"The first row of numbers changed it is now "<<Level <<"/"<< MaxLevel <<"...\"\n";
        std::cout << "Golum: \"The sum of the new numbers we need are: " << CodeSum <<"\"\n";
        std::cout << "Golum: \"The next product is: "<< CodeProduct<<"\"\n";
        std::cout << "Golum: \"You can do it...\"\n";
        std::cout << "Golum: \"You have " << Lifes << " chances left\"\n\n";
        break;
    case 10:
        std::cout << "\n Golum: \" It is STILL not OPEN\"\n";
        std::cout << "Golum: \"It is now "<<Level <<"/"<< MaxLevel <<"... \n (Golum seems excided)\"\n";
        std::cout << "Golum: \"The sum of the new numbers we need are: " << CodeSum <<"\"\n";
        std::cout << "Golum: \"The next product is: "<< CodeProduct<<"\"\n";
        std::cout << "Golum: \"LAST One you BETTER get this Hummie\"\n";
        std::cout << "Golum: \"You have " << Lifes << " chances left\"\n\n";
        break;
    } 
}

void WinGame()
{
    std::cout << "Golum: YES, YES, YES!!! It worked...\n";
    std::cout << "While Golum is basking in the aura of The Ring you make your escape...";
}

void LoseGame ()
{
    std::cout <<"Golum: YOU STUPID HUMAN!!!(Golum starts running at you) DIE!!!\n (He attacks you with his bare hands and bites out your Throat) \n You died" ;
}


bool PlayGame (int Difficulty, int MaxLevel,int Lifes) 
{
// user defined variables declarations 
    srand(time(NULL));
    int CodeA = (1+(rand()%Difficulty));
    int CodeB = (1+(rand()%Difficulty));
    int CodeC = (1+(rand()%Difficulty));
    
    
    int CodeSum = CodeA + CodeB + CodeC;
    int CodeProduct = CodeA * CodeB * CodeC;
    PrintIntroduction(Difficulty,CodeSum,CodeProduct, MaxLevel, Lifes);
        // player inputs and input manipulation delarations
    int PlayerGuess;
    int GuessA, GuessB, GuessC; //  for player input comparison 
    int GuessSum, GuessProduct;
    // Player input for guess
    std::cout << "Player: My first guess is:";
    std::cin >> GuessA;
    std::cout << "Player: The second one is:";
    std::cin >> GuessB;
    std::cout << "Player: The third one should be:";
    std::cin >> GuessC; 
    GuessSum = GuessA+GuessB+GuessC;
    GuessProduct = GuessA*GuessB*GuessC;
   // std::cout << "Your 3 guesses are: " << GuessA << ", " << GuessB << ", " << GuessC << std::endl;
   // std::cout << "The sum of your guesses are: " << GuessSum << std::endl;
   // std::cout << "The product of your guesses are: " << GuessProduct << std::endl;

   // Guess Check
    if (Lifes > 0)
    {
        if ((CodeSum == GuessSum) && (CodeProduct == GuessProduct))
        {
            return true;
        }
        else
        {
            return false;
        }
    }    

}

int main() 
{  
    int LevelDifficulty = 1;
    const int MaxLevel = 10;
    int Lifes = 3;
    while (LevelDifficulty <= MaxLevel)
    {
        bool bLevelComplete;
        bLevelComplete =PlayGame(LevelDifficulty,MaxLevel,Lifes);
        std::cin.clear(); // clears any errors
        std::cin.ignore(); // discards the buffer

        if (bLevelComplete)
        {
           ++LevelDifficulty;
            std::cout << "\nYou completed the level\n\n";
            if (LevelDifficulty = MaxLevel )
            {
                WinGame();
            }
            
        }
        else
        {
            Lifes--;
            std::cout << "\n Golum: \"You gave me the wrong code try again\"";
            if (Lifes == 0)
            {
                LoseGame();
                return 0;
            }
        }
        

               
    }
    
    //PlayGame();
    return 0;
}

Hello everyone, Mine is quite basic and there is no image.

#include
#include

void PrintIntroduction(int Difficulty)
{
std::cout << “\n You are a secret agent breaking into a level " << Difficulty;
std::cout << " secure server room.\n You need to enter the correct code to continue.\n\n”;
}

bool PlayGame(int Difficulty)
{

PrintIntroduction(Difficulty);

// Welcome to the numbers game 
const int CodeA = rand() % Difficulty + 1;
const int CodeB = rand() % Difficulty + 1;
const int CodeC = rand() % Difficulty + 1;

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

// Print CodeSum and CodeProduct to the terminal

std::cout << "\n + There are 3 numbers in the code";
std::cout << "\n + The codes add up to " << CodeSum;
std::cout << "\n + The codes multiply to give " << CodeProduct << std::endl;

// Store Player Guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;

// Check if the players guess is correct
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;

if(GuessSum == CodeSum && GuessProduct == CodeProduct)
{
    std::cout << "Correct proceed" << std::endl;
    return true;
}
else
{
    std::cout << "Access denied\n";
    return false;
}

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

int LevelDifficulty = 1;
int const MaxDifficulty = 5;

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

    if  (bLevelComplete) 
    {
        ++LevelDifficulty;
    }

}
std::cout << "Well done you're in! Get the files and leave";
return 0; 

}

Well, so I haven’t changed much in difficulty randomization and level 5 seems to be a pretty hard.

:slight_smile:

This my TripleX game. Thank you, Gavin, for teaching me how to build the game.

#include<iostream>
#include<chrono>
#include<ctime>

void Introduction (int Difficulty) 
{
    std::cout << "You have found a level " << Difficulty;
    std::cout << " bomb in your school\nThere is only 1 minute left before it starts to explode";
    std::cout << "\nYou have no time to tell other people...";  
    _sleep(5000);
    std::cout << "\nBut, you can shut it off by yourself if you enter a correct combination...";
     _sleep(2000);
};

void AboveLevel1Introduction (int Difficulty)
{
    std::cout << "This time you found a level " << Difficulty << " bomb.";
};

bool PlayGame (int Difficulty)
{
    if (Difficulty ==1 )
    {
        Introduction(1);
    } 
    else
    {
        AboveLevel1Introduction(Difficulty);
    };
    
    const int CodeA = rand() % (Difficulty + 2) + Difficulty;
    const int CodeB = rand() % (Difficulty + 2) + Difficulty;
    const int CodeC = rand() % (Difficulty + 2) + Difficulty;

    int CodeSum = CodeA + CodeB + CodeC;
    int CodeProduct = CodeA * CodeB * CodeC;
    
    std::cout << "\n+ There are 3 numbers in the combination";
    std::cout << "\n+ They add-up to: " << CodeSum ;
    std::cout << "\n+ Their product is: " << CodeProduct << std::endl;
    
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;

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

    if (GuessSum == CodeSum && GuessProduct == CodeProduct )
    {
        std::cout << "+++ Congratulation! You've shut the level " << Difficulty << " bomb off. \n\n";
        return true;
    }
    else 
    {
        std::cout << "--- Be Careful! You entered a wrong combination.\n\n";
        return false;
    };
};

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

    const int MaxLevel = 5;
    int LevelDifficulty =1;
    
    while (MaxLevel >= LevelDifficulty)
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear();
        std::cin.ignore();
        
        if (bLevelComplete && LevelDifficulty < MaxLevel)
        {
            ++LevelDifficulty;
            std::cout << "*** Let's move to the next room.\n\n";
        }
        else if (bLevelComplete && LevelDifficulty == MaxLevel)
        {
            std::cout << "+++ You've shut all the bombs off and saved the school. Well Done!!! ";
            ++LevelDifficulty;
        }
        else
        {
            std::cout << "*** Now try again.\n\n";
        };
    }
    return 0;
}

Here is my final TripleX Game using the rand() function (Which I think is working and giving me a good mental challenge), and it works pretty well!
This has been an informative and helpful way of introducing beginners to C++ Programming, but this course is also a great refresher for people who want to touch-up their programming skills.
Thanks for keeping this course up to date and full of challenge!

#include <iostream> 
#include <ctime>

void PrintIntroduction(int Difficulty) {
//Print welcome messages to the terminal and introduce the game.

    std:: cout << "\n\nYou are a legendary super-hacker spy who is famous across the world. Your rival has hidden away all of your belongings";
    std:: cout << " in a foolproof, Level " << Difficulty;
    std:: cout << " Triple X Code Safe! But is it truly foolproof? Not for a super-hacker spy such as yourself!\n";
    std:: cout << "There look to be five levels to solving this lock.\n";
    std:: cout << "It appears that the perpetrator of this crime has left some clues for you to solve... \"Go ahead, solve my riddles!\"";
   

}

bool PlayGame(int Difficulty) {
    PrintIntroduction(Difficulty);

    //Declare 3 Number Code
    const int Code_A = rand() % Difficulty + Difficulty;
    const int Code_B = rand() % Difficulty + Difficulty;
    const int Code_C = rand() % Difficulty + Difficulty; 

    const int Code_Sum = Code_A + Code_B + Code_C;
    const int Code_Product = Code_A * Code_B * Code_C;

    //Print sum and product to the terminals.
    std:: cout << std:: endl;
    std:: cout << "There are three numbers in the code.\n";
    std:: cout << "\n The codes add up to: " << Code_Sum;
    std:: cout << "\n The codes multiply to give: " << Code_Product << std:: endl;
    
     //Store Player's guess.
    int Guess_A, Guess_B, Guess_C;
    std:: cin >> Guess_A >> Guess_B >> Guess_C;

    int Guess_Sum = Guess_A + Guess_B + Guess_C;
    int Guess_Product = Guess_A * Guess_B * Guess_C;

    //Check if player's guess is correct.
      if (Guess_Sum == Code_Sum && Guess_Product == Code_Product) {
        std:: cout << "You have inputted the numbers: " << Guess_A << Guess_B << Guess_C;
        std:: cout << "\nKli-click! The code was correct and one of the locks is undone! Hurrah! Now move onto the next lock!";
        return true;
    }
    else {
        std:: cout << "You have inputted the numbers: " << Guess_A << Guess_B << Guess_C;
        std:: cout << "\nWait, why is something smouldering inside the safe... OH NOOOO!! You've failed and set off a trap that burned up your belongings!!\n";
        std:: cout << "No, that is merely you over-dramatising the dangers here. Your rival surely doesn't intend to do you harm - it seems they're letting you try again.";
        return false;
    }
} 

int main() {

    srand(time(NULL)); // Create a new Random Sequence based on the time of day.
    int Level_Difficulty = 1;
    const int Max_Difficulty = 5;

    //Loop game until all levels are completed.
    while (Level_Difficulty <= Max_Difficulty) {
        
        bool bLevel_Complete = PlayGame(Level_Difficulty);
        std:: cin.clear(); //Clears any Error
        std:: cin.ignore(); //Discards the Buffer

       if (bLevel_Complete){
            Level_Difficulty++;
        }
    }

    std:: cout << " TADA!!! The nightmare is over, you have solved the puzzles and all your belongings are safe!";
    std:: cout <<" You have well and truely earned your vacation! Congratulations!!";
    return 0;
}

So here is my first game and just to get the hang of things I went in as basic as possible.

Code:

#include
#include

void PrintIntroduction(int Difficulty)
{
std::cout << “\n You are a secret agent breaking into a level " << Difficulty;
std::cout << " secure server room.\n You need to enter the correct code to continue.\n\n”;
}

bool PlayGame(int Difficulty)
{

PrintIntroduction(Difficulty);

// Welcome to the numbers game 
const int CodeA = rand() % Difficulty + 1;
const int CodeB = rand() % Difficulty + 1;
const int CodeC = rand() % Difficulty + 1;

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

// Print CodeSum and CodeProduct to the terminal

std::cout << "\n + There are 3 numbers in the code";
std::cout << "\n + The codes add up to " << CodeSum;
std::cout << "\n + The codes multiply to give " << CodeProduct << std::endl;

// Store Player Guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;

// Check if the players guess is correct
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;

if(GuessSum == CodeSum && GuessProduct == CodeProduct)
{
    std::cout << "Correct proceed" << std::endl;
    return true;
}
else
{
    std::cout << "Access denied\n";
    return false;
}

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

int LevelDifficulty = 1;
int const MaxDifficulty = 5;

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

    if  (bLevelComplete) 
    {
        ++LevelDifficulty;
    }

}
std::cout << "Well done you're in! Get the files and leave";
return 0; 

}

1 Like

Here is my code for the game!!

#include <iostream>
#include <ctime>

void PrintIntroduction(int FirstPass, bool NewLevel, int Difficulty)
{
    if (FirstPass == 1)
    {
    std::cout << "                         ___________       .__         .__            ____  ___                           \n";
    std::cout << "                         \\__    ___/______ |__|______  |  |    ____   \\   \\/  /                           \n";
    std::cout << "  ______   ______   ______ |    |  \\_  __ \\|  |\\____ \\ |  |  _/ __ \\   \\     /   ______   ______   ______ \n";
    std::cout << " /_____/  /_____/  /_____/ |    |   |  | \\/|  ||  |_> >|  |_ \\  ___/   /     \\  /_____/  /_____/  /_____/ \n";
    std::cout << "                           |____|   |__|   |__||   __/ |____/ \\___  > /___/\\  \\                           \n";
    std::cout << "                                               |__|               \\/        \\_/                           \n";
    std::cout << "\nYou are in a secret underground bio facility.. Mutated researchers are at your back!!!\n";
    } 
    std::cout << 5 - (Difficulty - 1) << " doors stand in your way to freedom.. " << "\n"; 
    
    if (NewLevel)//to have a timely posting of message effect on the game. not on every turn.
    {
    std::cout << "You have reached the door but you must enter the correct code to escape..\n";
    }
}

bool PlayGame(int FirstPass, bool NewLevel, int Difficulty)
{
   PrintIntroduction(FirstPass, NewLevel, Difficulty);

    //Declare 3 number code
    const int CodeA = rand()%Difficulty + Difficulty;
    const int CodeB = rand()%Difficulty + Difficulty;
    const int CodeC = rand()%Difficulty + Difficulty;

    //print sum and product\ to the terminal
    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA*CodeB*CodeC;
    
    std::cout << "\n+ There are 3 numbers in the code..\n";
    std::cout << "+ The codes add-up to: " << CodeSum << "\n";
    std::cout << "+ The codes multiply to give: " << CodeProduct << "\n\n";


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

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

    //Cheak if Guess is Correct
    if(GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\n---You opened the Door!!---\n\n" ;
        return true;
    }else
    {
        std::cout << "\n---The mutants are at your back!!---\n\nThe door is Locked!! Try again!!\n";
        return false;
    }
}

//main function. intialize variables and print welcome message
int main()
{ 
    
    srand(time(NULL));
    
    int LevelDifficulty = 1;
    int MaxDifficulty = 5;
    bool LevelPassed = true;
    int TryNumber = 1;
    int Exit;

      while (LevelDifficulty <= MaxDifficulty) //loop game until all levels are completed
   {
        bool bLevelComplete = PlayGame(TryNumber, LevelPassed ,LevelDifficulty);
        std::cin.clear(); //clear my errors
        std::cin.ignore(); //discard the buffer

        if (bLevelComplete)
        {
           ++LevelDifficulty;
           LevelPassed = true;
           ++TryNumber;
        }else
        {
            LevelPassed = false;
            ++TryNumber;
        }    
   }
    std::cout << "\n---Congratulations!!---";
    std::cout << "\n-----------------------\n\nYou cleared all doors and escaped to your freedom..\n\n\n";
    std::cout << "Press any key to exit\n\n";
    std::cin >> Exit;

            return 0;
        }
1 Like

#include
#include
using namespace std;

void PrintIntroduction(int Difficulty)
{
cout << "You are a secret agent breaking into a Level “<< Difficulty ;
cout << " secure room…\nEnter the correct code to continue…”;
}

bool PlayGame(int Difficulty)
{
PrintIntroduction( Difficulty);
//Numbers to be achieved
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;

cout << "\n* There are three numbers in the code\n";
cout << "* The codes add-up to: "<< CodeSum;
cout << "\n* The codes multiply to give: " << CodeProduct << endl;

//Store player guesses
int GuessA, GuessB, GuessC;
cin >> GuessA >> GuessB >> GuessC;

cout << "\nYou Entered: "<< GuessA << " " << GuessB << " " << GuessC ;

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

//Check if the players guess is correct
if(GuessSum == CodeSum && GuessProduct == CodeProduct)
{
    cout << "\nYou Win!\n";
    cout << "Get ready for the next level\n";
    return true;
}
else
{
    cout << "\nYou failed!\n";
    cout << "You can try again, Agent";
    return false;
}

}

int main()
{
srand(time(NULL)); //Create new random sequence based on time play
int LevelDifficulty = 1;
bool bLevelComplete;
int const MaxLevel = 5;
while(LevelDifficulty <= MaxLevel)
{

    bLevelComplete = PlayGame( LevelDifficulty);
    std::cin.clear(); //clears any error
    std::cin.ignore(); //Discards the buffer

    if (bLevelComplete)
    {
        ++LevelDifficulty;
    }
}    
cout << "Congratulations Agent, You've hacked into the most sophisticated system in the world!!";
return 0;

}

1 Like

Hey everyone! This is what I had at the end of this section, pretty much followed the example but modified a couple of things:

#include <iostream>
#include <ctime>

void PrintIntroduction(int Difficulty)
{
    // Print welcome messages
    if (Difficulty == 1)
    {
    std::cout << "___________      .__       .__         ____  ___ \n";
    std::cout << "\\__    ___/______|__|_____ |  |   ____ \\   \\/  / \n";
    std::cout << "  |    |  \\_  __ \\  \\____ \\|  | _/ __ \\ \\     /  \n";
    std::cout << "  |    |   |  | \\/  |  |_> >  |_\\  ___/ /     \\  \n";
    std::cout << "  |____|   |__|  |__|   __/|____/\\___  >___/\\  \\ \n";
    std::cout << "                    |__|             \\/      \\_/ \n\n";
    std::cout << "You are a secret agent breaking into a secure server room. \nYou need to enter the correct code to continue. \n";
    }
    std::cout << "Current difficulty level: " << Difficulty << std::endl;
}

bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);

    // Declaring variables for code numbers
    const int NumberA = rand() % Difficulty + 1;
    const int NumberB = rand() % Difficulty + 1;
    const int NumberC = rand() % Difficulty + 1;

    const int NumberSum = NumberA + NumberB + NumberC;
    const int NumberProduct = NumberA * NumberB * NumberC;

    // Print sum and product of code numbers
    std::cout << "\nThere are 3 numbers in the code. \n";
    std::cout << "The numbers add up to: " << NumberSum;
    std::cout << "\nThe numbers multiply to give: " << NumberProduct << std::endl << std::endl;

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

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

    // Check if guess is correct
    if (GuessSum == NumberSum && GuessProduct == NumberProduct)
    {
        if (Difficulty < 10)
        {
        std::cout << "You are correct! You have moved to the next level.\n\n\n";
        return true;
        }

        if (Difficulty == 10)
        {
        std::cout << "You are correct!\n";
        return true;
        }
    }
    else
    {
        std::cout << "Wrong! Please try again.\n\n\n";
        return false;
    }
}

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

    int LevelDifficulty = 1;
    const int MaxDifficulty = 10;

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

        if (bLevelComplete)
        {
            // Increase difficulty
            ++LevelDifficulty;
        }
        
    }

    std::cout << "Well done! You have completed the game.";
    return 0;
}

:grinning:

1 Like

Proud
I’m so proud of myself. I am shocking at math but i did all 5 levels :smiley:

1 Like
#include <iostream>
#include <ctime>

void GameIntro (int Difficulty)
{
    //text output to inform of the games intention.
    std::cout << "________________________________________________________________________________________________________\n";
    std::cout << "\n\nEvening Sergeant; we've been waiting for your arrival.\n";
    std::cout << "The enemy has infiltrated the orbital station via the hab ring, all military personnel have been locked out and are unable to gain access.\n";
    std::cout << "Your job is to hack into the encrypted locking mechanisms to allow access and a successful take back of the hab ring.\n";
    std::cout << "You'll have to keep in mind we have unconfirmed reports of civilian activity inside the ring,\n";
    std::cout << "we cannot confirm the enemy's knowledge on this; you must act fast and keep it covert.\n";
    std::cout << "Good luck sergeant!! do not fail.\n\n";

    std::cout << "                           ______\n";                     
    std::cout << "   _________        .---^^^      ^^^---.\n";             
    std::cout << "  :______.-':      :  .--------------.  :\n";           
    std::cout << "  | ______  |      | :                : |\n";            
    std::cout << "  |:______B:|      | |  Enter Access  | |\n";           
    std::cout << "  |:______B:|      | |  Password:     | |\n";           
    std::cout << "  |:______B:|      | |                | |\n";          
    std::cout << "  |         |      | |      ----      | |\n";           
    std::cout << "  |:_____:  |      | |                | |\n";           
    std::cout << "  |    ==   |      | :                : |\n";            
    std::cout << "  |       O |      :  '--------------'  :\n";             
    std::cout << "  |       o |      :'---...______...---'\n";              
    std::cout << "  |       o |._.-¬___|'            '| _\n";             
    std::cout << "  |'-.____o_|   '-.   '-...______...-'  `-._\n";    
    std::cout << "  :_________:      `.____________________   `-.___.-.\n";
    std::cout << "                   .'.eeeeeeeeeeeeeeeeee.'.      :___:\n";
    std::cout << "                 .'.eeeeeeeeeeeeeeeeeeeeee.'.\n";        
    std::cout << "                :____________________________:\n\n";

    std::cout << "Firewall severity: " << Difficulty << "\n\n";
}
bool PlayGame (int Difficulty)
{
    GameIntro (Difficulty);


    // Declaration of a 3 digit code for in game progression.
    const int CodeDigitA = rand() % Difficulty + Difficulty;
    const int CodeDigitB = rand() % Difficulty + Difficulty;
    const int CodeDigitC = rand() % Difficulty + Difficulty;

    // Hint for player to decipher code in form of multiplication and addition. 
    const int CodeOrderSum = CodeDigitA + CodeDigitB + CodeDigitC;
    const int CodeOrderMult = CodeDigitA * CodeDigitB * CodeDigitC;

    std::cout << "\nPlease enter access code to enter sytem overide, 3 digit code accepitble please proceed to enter.\n\n";
    std::cout << "The codes digits add up to: " << CodeOrderSum << "\n" << "And multiply to: " << CodeOrderMult << "\n\n";

    // Decleration of code input values.        
    int GuessA, GuessB, GuessC;

    // Player code guess input
    std::cout << "Manual overide passcode first digit entry: ";
    std::cin >> GuessA;
    std::cout << "\nManual overide passcode second digit entry: ";
    std::cin >> GuessB;
    std::cout << "\nManual overide passcode third digit entry: ";
    std::cin >> GuessC;
    std::cout << "\n";

    // Decleration of player guess sum and multiplication values
    int GuessSum = GuessA + GuessB + GuessC;
    int GuessMult = GuessA * GuessB * GuessC;

    // result of player guess 
    std::cout << "The value's you entered had the sum of: " << GuessSum << "\n" << "And the multiplication of: " << GuessMult << "\n";
    std::cout << "________________________________________________________________________________________________________\n";

        // If statement to inform player of if they have progressed or not.
        if (GuessSum == CodeOrderSum && GuessMult == CodeOrderMult)
        {
            std::cout << "Access Granted!\n" << "Manual overide in progress await further instruction's.\n\n";

            return true;
        }
        else
        {     
            std::cout << "Overide system lockout, unable to proceed.\n";
            return false;
        } 
}
int main ()
{
    srand(time(NULL));
    int LevelDifficulty = 1;
    const int MaxLevelDifficulty = 5;

    //Loops game until level 5 reached and all complete true.
       while (LevelDifficulty <= MaxLevelDifficulty)
    {
        bool BLevelComplete = PlayGame(LevelDifficulty);

        std::cin.clear();
        std::cin.ignore();

        if (BLevelComplete)
        {
            ++LevelDifficulty;
        }
    }
    std::cout << "SYSTEM OVERIDE SUCCESSFUL PROCEED TO ENTER HAB RING.";

    return 0;
}
1 Like

Great course so far! I have a little programming experience in other languages so this was helpful to learn the syntax.

#include <iostream>
#include <ctime>

void PrintIntroduction(int Difficulty)
{
    // Output introduction text to the terminal
    /*
            (
         )    )
      _.(--"("""--.._
     /, _..-----).._,\
    |  `'''-----'''`  |
     \               /
      '.           .'
        '--.....--'
     */
    std::cout << "  _______   _       _     __   __\n";
    std::cout << " |__   __| (_)     | |    \\ \\ / /\n";
    std::cout << "    | |_ __ _ _ __ | | ___ \\ V /\n";
    std::cout << "    | | '__| | '_ \\| |/ _ \\ > <\n";
    std::cout << "    | | |  | | |_) | |  __// . \\\n";
    std::cout << "    |_|_|  |_| .__/|_|\\___/_/ \\_\\\n";
    std::cout << "             | |\n";
    std::cout << "             | |\n";
    std::cout << "             |_|\n";

    std::cout << "New guests are arriving to the restaurant you work for, the Briney Schnitzel. \n";
    std::cout << "You must create a new menu item that appeals to a special table reserved for mathemeticians. \n";
    std::cout << "So let's come up with a few courses of numbers...";
}

bool PlayGame(int Difficulty) 
{
    // 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;

    // Output sum and product to the terminal
    std::cout << "\n\n<< LEVEL " << Difficulty << " >>\n\n";
    std::cout << "+ There are three numbers in the course. \n";
    std::cout << "+ The numbers add up to: " << CodeSum << "\n";
    std::cout << "+ The numbers 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 << "\nWell done! The guests are delighted.";
        return true;
    } 
    else 
    {
        std::cout << "\nWhoops. That didn't go over so well...";
        return false;
    }
}

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

    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;

    PrintIntroduction(LevelDifficulty);

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

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        else {
            std::cout << "\nLet's re-fire this meal...";
        }
    }

    std::cout << "\n\nCongratulations on a five course meal of delectable numerals. Complements to the chef!";

    return 0;
}
1 Like

This was so much fun to write! Here’s what I came up with.

#include <iostream>
#include <ctime>

//Using \n MUST BE *INSIDE* of a string ""!

void PrintIntroduction(int Difficulty)
{
//ASCII Art

    std::cout << "########################################################################################################\n";
    std::cout << "#    ::::::::::::::::::::::::                                                                          #\n";
    std::cout << "#    ::                    ::                                                                          #\n";
    std::cout << "#    ::                    ::                                                                          #\n";
    std::cout << "#    ::::::::::     :::::::::                                                                          #\n";
    std::cout << "#             :     :                                                                                  #\n";
    std::cout << "#             :     :                                                                                  #\n";
    std::cout << "#             :     :                                                                                  #\n";
    std::cout << "#             :     :                                                          :::::        :::::      #\n";
    std::cout << "#             :     :                                                           :   :      :   :       #\n";
    std::cout << "#             :     :                   ::::             ::::                    :   :    :   :        #\n";
    std::cout << "#             :     :  ::::             :  :             :  :                     :   :  :   :         #\n";
    std::cout << "#             :     :  :   :::::::::::  ::::             :  :                      :   ::  :           #\n";
    std::cout << "#             :     :  :              :       :::::::    :  :    ::::::::::         :     :            #\n";
    std::cout << "#             :     :  :     ::::     : ::::  :      :   :  :   :          :         :   :             #\n";
    std::cout << "#             :     :  :    :    :    : :  :  :  ::: :   :  :   :    :::   :         :   ::            #\n";
    std::cout << "#             :     :  :   ::     ::::  :  :  :  : : :   :  :   :          :        :      :           #\n";
    std::cout << "#             :     :  :  :             :  :  :  ::: :   :  :   :   :::::::        :   ::   :          #\n";
    std::cout << "#             :     :  :  :             :  :  :      :   :  :   :  :              :   :  :   :         #\n";
    std::cout << "#             :     :  :  :             :  :  :  ::::    :  :   :  :     ::::    :   :    :   :        #\n";
    std::cout << "#             :     :  :  :             :  :  :  :       :  :   :  ::::::  ::   :   :      :   :       #\n";
    std::cout << "#             :::::::  ::::             ::::  ::::       ::::    ::::::::::    :::::        :::::      #\n";
    std::cout << "########################################################################################################\n";

// The plotline
    std::cout << "\n\nYou are an undercover government operative, working at the Department of Undercover Operations. A code has recently been sent to you, and you do not have the key. You decide to hack into different top security systems and military bases to try and find the key.\n";
    std::cout << "Obviously, these places are protected by a lot of security. We'll do the heavy lifting--all YOU need to do is enter a three digit code. Luckily, the people that created these systems are so sure they won't be hacked that they left clues. Here's level " << Difficulty << ".\n\n";
}

bool PlayGame(int Difficulty)
{

    PrintIntroduction(Difficulty);

   // The math/variables
    const int FirstAnswer = rand() % Difficulty + Difficulty;
    const int SecondAnswer = rand() % Difficulty + Difficulty;
    const int ThirdAnswer = rand() % Difficulty + Difficulty;
    const int SumAddition = FirstAnswer + SecondAnswer + ThirdAnswer;
    const int SumMultiplication = FirstAnswer * SecondAnswer * ThirdAnswer;

    // The answers being outputted
    std::cout << "+ There are three numbers in the code to figure out.\n";
    std::cout << "+ The codes add up to " << SumAddition << std::endl;
    std::cout << "+ If you multiply the codes, it gives you " << SumMultiplication << std::endl;
    std::cout << "+ Do the math and input your answers, with a space or enter between each number.\n";

    //Player's answers
    int GuessFirst, GuessSecond, GuessThird;
    std::cin >> GuessFirst >> GuessSecond >> GuessThird;
    std::cout << "You typed " << GuessFirst << GuessSecond << GuessThird << " into the computer.";
    int GuessAdd = GuessFirst + GuessSecond + GuessThird;
    int GuessMultiply = GuessFirst * GuessSecond * GuessThird;
    
    //Winning conditions
    if (GuessAdd == SumAddition && GuessMultiply == SumMultiplication)
    {
      std::cout << " The computer slowly processes your code...\n";
      std::cout << "-+-You win! The computer quickly scans the database...but find nothing. Huh.-+-\n\n";
      return true;
    }
    else
    {
        std::cout << " The computer slowly processes your code...\n";
        std::cout << "-+-The security system caught you! Try again? Enter \"triplex\".-+-\n\n";
        return false;
    }
}

int main()
{
    srand(time(NULL));
    int LevelDifficulty = 1;
    const int MaxDifficulty = 10;

    while (LevelDifficulty <= MaxDifficulty)    //Loop game until all levels are completed.
    {
        bool bLevelCompletion = PlayGame(LevelDifficulty);
        std::cin.clear();
        std::cin.ignore();

        if (bLevelCompletion) {
            ++LevelDifficulty;
        }
    }

    std::cout << "Congratulations! You examined all 10 databases, but unfortunately, nothing came up that would be remotely useful. Hmm...Oh! Maybe this mysterious note could be of help...\n\n";
    std::cout << "YOU WON!";
   
    return 0;
}

NOTE: I tried playing the game after this, and couldn’t get past level four. I changed the rand() difficulty to

    const int FirstAnswer = rand() % 12 + 1;
    const int SecondAnswer = rand() % 12 + 1;
    const int ThirdAnswer = rand() % 12 + 1;
1 Like

I love writing TripleX! It is so much fun! I love how this game really makes you think as the levels get harder.

1 Like

made a couple edits to difficulty and made the story about a kid trying to hack a computer to change their grade

#include < iostream>
#include < ctime>

void PrintIntroduction(int Difficulty)
{
//Introduction
std::cout << “Mnznn##znxnxnnnW@WWMMMMxMMMMMxznznnnnxn+#nnxxxnMxz#zzzzzMz+nMnnzM#xxM#i;::z+,+izWWWMnMMMxWxxMnzMMMMxnnMMMMWWWWnzMMMMMWWWxnnzzzzxMWWWWMMMn+zz#z#zn\n";
std::cout << "Mnznz#z#n#;
##n+;i;;MM+,;;:zMMxx#::,;nnnnn#+i;::;;::;;,::;xWz::;;:+Mi:;;:::,i
,.:,;;i
zxxn;;;:;+MMxx;::;;MWMMM;;;+WWWWMi;;::nMxi;;iiWn++#MMMWMMnxM@\n”;
std::cout << “MMnzzz#z+iiiii*,:i*:MMi,ii:#xnx#.:;;:#nnnn*,.,;;;;;;,.:;;,#n,:;;.;,:;:::::,::::;;:,ix+.;;;i:xMx+,:;ii,xxMM+.:;i:WWMMx,;i;::+,;i:Wz#+nzzzMWWWWW\n";
std::cout << "Mzzzz#nz
**#z+#,:;;;Mx:::;:xxxn:,::::nzn+.,:::::::::.:::i+,:::,::.,::::::::i.,:::::::::,n;,::::innn,:::::nzMn,:,:;.#z#z#,:::;:+i,;;;i#;:#znnnnxW@@@\n";
std::cout << "xznnznn#xnnnz#
,:::#xz,#nnn+.,+z##,…,:.,,.i+.,…,:…,…,z:,nni,:znzn:,:.+Mx:,::;xz,:::nz#i;:,::;i#\n";
std::cout << "Mzxnn@xzxMWMMxi,:;xni.,nnzz,…,.+z#;…,.;z#;;#
,.,;;…,+#:…,##+:,i+i…,.;z#…,.+,…,n+…,iznz+…,+#zn,.,#.,:;MWWW@@WWMnz++xW\n”;
std::cout << “Mxnnn@xnMWMn++:,:;,.,zxn;…:.,;z+…:+##z#+,…,…;n…,;,…,;i:…,i+:……,:z:…,.nnz,…,.,.zn#…,ii.,:iMWMMWWW@@@@@@WWW\n”;
std::cout << “WWxWWWxnMMWMMn…,;Mx+…,n..,n;###+#++…;nx,…i...........:*…i…Mx;…;..iWM*...,,,,,,,,,iWWWWWWWWWWWWMWMW\n"; std::cout << "MMn###x@@WWMx*.,,,,,,,.,,;Mn,...;+....i...,,#xz#+#+i.....,;:xnz..........,,i:.........,:#,..,...,.......,#M+...,zi..,,Mxi..,;:..,.,,:*WWWWWWWWW@@WWMM@\n"; std::cout << "#+#+#zzxWWWMM*xMMnzzznnn*#zi#xxni*zxn*,:xxninxxxz#+;zxnznnn:#z+innn#######ii#xnnnnnnni,#z;nn#:nn**nni#nniz#:xxxz+ixxx*znixxx++nxz+xM#zMMMWWWW@@@@W@W@@\n"; std::cout << "++#zxMMxWWMxx*zzz+zi:#zz*z+*zzzzzz###++i###+xxMMMxn.##z;###*+z#*##+i+++*ii*;##z**;*##;;z+*+#*,#####+;###iz:*zzzzzz##z+zz*zzz+#+zzzzn#xxMMWW@@@@@@@@@@@\n"; std::cout << "xMWMMMMWWMMMz,;iizxx:;;;;z.;;;;;;::::;,,::;:*i****+,:::#:::;;#+,,::.i;i;::;.::;*#+,:;:,ni,,:;;::;;:,,:::,;,;::::::,:;;##,:;;zz:i;;ii#MWWW@@@@@@@@@@@@@\n"; std::cout << "MMMxxMWWWMMM+,,:;xxn,,,,*;,,,:zi;i:..,....,,,,.,,,;..,,z:..,,;n..,…,:;…znn…,.z:…i;....i.…,.i#+:.,++…,:xx,.,:::+@@@@@@@@@@@@@@@@@\n”;
std::cout << “WMxMxxMWWMMMi.,Mx#…,.,.#xnzz;…,........;i…iz+…;Mi…i…:zzM;…:..+i.......,zxzz+....ii.,iMM*.,::z@@@@@@@@@@@@@@@@@\n";
std::cout << “MMnxMWMWMMxx:.,.zMx+…,…innz+i...z*,.......*;``.+z#i....#xi........#;…i+zM#…#,..;*``.,n;``.*,Mxzzz:…;;`…#Mxz,.,WWWW@@@@@@@@@@@@@@\n";
std::cout << "WMM@WWMMMMMx####xxnz###i,;##+iii
*+,+xMn#######z+##++++#zz#zxx#++##+#+i*++iMn*++++++###++##zz+###z####nxxnnz++i;###zznxxxz#z:#WWW@@@@@@@@@@@W@WW\n”;
std::cout << "WWMx@@WWWMxzzzn#xxxzz
*++#ii+niiixMMMxxxxxxxnn##z++#+#nxMM+:nnnnz+++:;:i:iW;++#++#####zzzxnzznnznnxxxxxxxxxxxxxxxxxxxxxMMWWW@@@@@@@@@@@WMxn\n";
std::cout << "WWM#M@WWWWWWWMMMMM#+z#zzzzz#;i
ni;
+#inWMxxxx+++
++##zz###nM#.:;#MMMi:
+:i:,izz;#+**+#M#+#zzz#znxnxMnnxnxxMMMxxxxxMxxxMxxxxMMMMMMWW@@@@@@@@@@WWMnnz\n”;
std::cout << “\nYou are a student who’s trying to hack into a level " << Difficulty;
std::cout << " firewall to change their grade\nEnter the correct code to contiue…\n”;
}

bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
//variables
const int CodeA = (rand() % (Difficulty + 2)) + 1;
const int CodeB = (rand() % (Difficulty + 2)) + 1;
const int CodeC = (rand() % (Difficulty + 2)) + 1;

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

//print out numbers
std::cout << std::endl;
std::cout << "+ There are 3 number in the code";
std::cout << "\n+ The codes add up to: " << CodeSum;
std::cout << "\n+ The product of the code is: " << CodeProduct << std::endl;

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

//Calculate sum and product of guesses
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;

if((GuessSum == CodeSum) && (GuessProduct == CodeProduct))
{
    //std::cout << "\n You're in Hackerman\n";
    return true;
}
else
{
    //std::cout << "\n Error! Invalid codes\n";
    return false;
}

}

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

int LevelDifficulty = 1;
const int MaxLevel = 6;
while (LevelDifficulty <= MaxLevel) // Loop game until all levels completed
{
    bool bLevelComplete = PlayGame(LevelDifficulty);
    std::cin.clear(); //clears any errors
    std::cin.ignore();//discards buffer

    if (bLevelComplete)
    {
        std::cout << "Great you got the code right\n\n";
        ++LevelDifficulty;
    }
    else
    {
        std::cout << "It looks like that code didn't work, try another one \n\n";
    }
    
    
}
 std::cout << "\n Great! You manage to get past all the firewalls and change your grade to a A+\n";
return 0;

}

I enjoyed this lesson very much. I made my version of Triple X a little differently. In my game, instead of looping for a set amount of rounds, my game continues to play until the player quits. It goes for an infinite amount of rounds! If the player enters something incorrectly, it will send the player back to level 1.

#include <iostream>
#include <ctime> 

using namespace std; 

void PrintIntroduction()
{
	cout << "Here's the situation: You're a cyber security agent who has to hack into a cyber terrorist group's server. " // Introduction to the player
		 << "Try to see how many levels you can access before you fail. \n"
		 << "You must enter a series of passwords in order to gain access to the server. Your software provides you with the following information: \n"; 
}

bool PlayGame(int Difficulty)
{
	int CodeA{ (rand() % Difficulty) + 1 }, CodeB{ (rand() % Difficulty) + 1 }, CodeC{ (rand() % Difficulty) + 1 }; // The three integers for the password
	const int CodeSum{ CodeA + CodeB + CodeC }, CodeProduct{ CodeA * CodeB * CodeC }; // Hints that will help the player 

	cout << " - The level " << Difficulty << " password consists of 3 integers \n"
		 << " - The product of the integers equals " << CodeProduct << '\n'
		 << " - The sum of the integers equals " << CodeSum << '\n'; // Print instructions to the player

	int GuessA{}, GuessB{}, GuessC{}; // Variables to hold the player's answer

	cout << "Enter your guess for what the password might be: \n"; // Recieve input from the user
	cin >> GuessA;
	cin >> GuessB;
	cin >> GuessC;

	const int GuessSum{ GuessA + GuessB + GuessC }, GuessProduct{ GuessA * GuessB * GuessC }; // Compare the player's answer to the correct answer

	if (GuessSum == CodeSum && GuessProduct == CodeProduct) // Check to see if the player was correct 
	{
		cout << "Congratulations! You correctly passed the level! \n";
		return true;
	}
	else
	{
		cout << "Incorrect. The correct answer was: " << CodeA << ' ' << CodeB << ' ' << CodeC << '\n'; 
		return false; 
	}

}

int main()
{
	char PlayerResponse = 'Y'; 
	int LevelDifficulty{ 1 }; 
	srand(time(NULL)); 

	PrintIntroduction(); 

	while (PlayerResponse == 'Y') // Continue playing the game until the player says 'N'
	{
		
		bool bLevelComplete = PlayGame(LevelDifficulty);
		cin.clear();
		cin.ignore();

		if (bLevelComplete)
		{
			++LevelDifficulty;
		}
		else
		{
			LevelDifficulty = 1; 
		}

		cout << "Play Again? 'Y' = Yes | 'N' = No ";
		cin >> PlayerResponse; 

	}

	return 0; 
}
1 Like
#include <iostream>

void IntroductionPrint() {

    // Introduction Texts
    std::cout << " Escape The Cave Game " << "\n =======================================";
    std::cout << "\nHi, Adventurer ... \nYou just trapped in this cave with 10 MUMMYs COFFINS. \n";
    std::cout << "Every Coffin Has 3 codes to guess, If you guess it right, You Kills the MUMMY \nIf you lose, The MUMMY Kills You!!";

}

bool TheGame(int Difficulty) {
    
    // Product Code
    int const CodeA = rand() % Difficulty + Difficulty;
    int const CodeB = rand() % Difficulty + Difficulty;
    int const CodeC = rand() % Difficulty + Difficulty;

    int const ProSum = CodeA + CodeB + CodeC;
    int const ProMult = CodeA * CodeB * CodeC;

    std::cout << "\n> The Coffin Number " << Difficulty << " Has Opened !!, Enter The 3 Codes : ";
    std::cout << "\n> The Codes Add-up to : " << ProSum;
    std::cout << "\n> The Codes Multiply to give : " << ProMult << std::endl;

    // Player Guess
    int GuessA, GuessB,GuessC;

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

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

    if ( ProSum == GuessSum && ProMult == GuessMult) {
        std::cout << "\nGreat work Adventurer!! You just killed the MUMMY!";
        return true;
    } else {
        std::cout << "\nOOps Adventurer!, The MUMMY just killed you, TRY AGAIN!!";
        return false;
    }

}

int main(int argc, char const *argv[]) {

    IntroductionPrint();

    int LevelDifficulty = 1;
    int const MaxLevel = 10;

    while (LevelDifficulty <= MaxLevel) {
       bool bLevelComplete = TheGame(LevelDifficulty);
        std::cin.clear(); // Clears any Errors
        std::cin.ignore(); // Discards the buffer

         if (bLevelComplete) {
            ++LevelDifficulty;
         }
    }
   
   std::cout << "\nWell Done!!, Now Escape the Hunted Cave with its Dead Mummy!";
    return 0;
}

Level 4 was hard. Level 5 was where my brain said ‘no more!!!’. I don’t like this type of thinking!

====

I put some extra work in to make it so the full intro only plays upon launch and after that an abbreviated ‘next password’ bit of text gets spit out instead.

void PrintNextPassword(int Difficulty, bool playIntro)
{
    if (playIntro = false)
    {
        std::cout << "\n\n"; 
        std::cout << "Slug: \"Here's the next password\n";
        std::cout << "Slug: \"It\'s a difficulty level " << Difficulty  << " password...\"\n";
        std::cout << "\n\n";  
    }
}

(it’s more involved than the snippet above, but you get the idea)

Also added some spacing to fit the vertical ‘resolution’ of my game to try and make it look like the screen is clearing after each attempt.

Privacy & Terms