How is your Triple X game looking?

Here is where I’m at. The story isn’t much and I haven’t done anything to crazy with the code.

#include<iostream>

void PrintIntroduction(int Difficulty)
{
    //prints story on screen
    std::cout << "\n\nYou were captured by some pirates and are locked in a level "<< Difficulty <<" cell with a 3 digit combination lock...\n";
    std::cout << "You have to enter the correct code to get out...\n";
    
    std::cout << " ______ \n";
    std::cout << " |_||_| \n";
    std::cout << " |_||_| \n";
    std::cout << "_|_||_|_\n\n";
}

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

    //code
    const int CodeA = rand();
    const int CodeB = rand();
    const int CodeC = rand();

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

    //print sum/product to terminal 
    std::cout << "You see some text on them...";
    std::cout << "\nWhat 3 numbers add up to " << CodeSum << "?";
    std::cout << "?\nAnd multiplie into " << CodeProduct << "?";

    //store player guess
    int GuessA, GuessB, GuessC;
    std::cout << "\nYour answer (Use spaces in between each): \n";
    std::cin >> GuessA >> GuessB >> GuessC;
    std::cout << "\nYou answered " << GuessA << GuessB << GuessC << "...";

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

    //checks to see if the player is right
    if(CodeSum == GuessSum && CodeProduct == GuessProduct)
    {
        std::cout << "\nYou put in the number and the lock opens. You can now get out of the cell...";
        
        if (Difficulty != MaxLevel)
        {
            std::cout << "\nExcept there is another door with another lock";
        }

        return true;
        
    }
    else
    {
        std::cout << "\nYou put in the number but it won't open. Must be wrong.\nYou should try again.";
        return false;
    }
}



int main()
{
    int LevelDifficulty = 1;
    int MaxLevel = 5;

    while(LevelDifficulty <= MaxLevel) //stops game when MaxLevel is met
    {
        bool bLevelComplete = PlayGame(LevelDifficulty, MaxLevel);
        std::cin.clear(); //clears any errors
        std::cin.ignore(); //discards the buffer

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }
    std::cout << "You've escaped the cells and go up to the deck (luckily the ship is sill in harbor). You've escaped.";
    return 0;

}
1 Like

My Triple X game is inspired by the constant delays at airports.

#include <iostream>
void PrintIntroduction(int Difficulty)
{
 //Print welcome messages

    
    std::cout << "\n\nYou are waiting in line to board your airplane.\n";
    std::cout << "       __|__\n--@--@--(_)--@--@--\n";
    std::cout << "As you arrive at the front of the line, the airline officer checking boarding passes informs you that you must complete a level " <<Difficulty;
    std::cout <<" puzzle in order to board as part of new TSA regulations...";
    
}
bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);
   
    //Declare 3 int variables
    const int CodeA = 4;
    const int CodeB = 2;
    const int CodeC = 3;
    
    
    //Now we assign the CodeSum and CodeProduct
    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;
    

    
    std::cout <<"\n\n+ There are 3 numbers in the code\n";
    std::cout <<"+ The sum is: ";
    std::cout <<CodeSum;
    std::cout <<"\n+ The product is: " <<CodeProduct << 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 guess to see if its correct
    if (GuessSum == CodeSum && CodeProduct == GuessProduct)
    {
        std::cout <<"\nThe airline officer congradulates you, but the level " <<Difficulty;
        std::cout <<" section of the plane has already boarded, and you will have to complete a level " <<Difficulty + 1;
        std::cout <<" puzzle in order to board.";

        return true;
    }
    else
    {
        std::cout<< "\nThe airline officer patronazingly tells you to try again.";
        return false;
    }
    
}


int main()
{
    const int MaxDifficulty = 5;
    int LevelDifficulty = 1;
    while (LevelDifficulty <= MaxDifficulty) //Loops the game until all levels are complete
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear(); //Clears any errors
        std::cin.ignore(); //Discards the input buffer

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }
    std::cout <<" The airline officer frowns and informs you that there is in fact a seat availible and allows you to board a long, tedius and uncomfortable flight.";
    
    return 0;
}

2 Likes

I added some extra line breaks in the outputted text and tried to make the ‘win’ message more of a transition from the ‘go on to the next level’ message that appears just before the win message.

#include <iostream>

void PrintIntroduction(int Difficulty)
{
    // Print Intro Messages to the terminal
    std::cout <<"\n";
    std::cout <<"                                           \n";
    std::cout <<"===========================================\n";
    std::cout <<"             YO SLUG!                      \n";
    std::cout <<"===========================================\n";
    std::cout <<"                                           \n";
    std::cout <<"                                           \n";
    std::cout <<"                                           \n";
    std::cout << "You are walking down the street one day...\n";
    std::cout << "You encounter a hip-looking slug with a backwards baseball cap.\n";
    std::cout << "Slug: \"PSST! Yo dawg! What's the password numba\"?\n";
    std::cout << "Slug: \"It\'s a difficulty level " << Difficulty  << " password...\"\n";
    std::cout << "\n\n";

}

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

    // Initialize 3 Number Code
    const int CodeA = rand();
    const int CodeB = rand();
    const int CodeC = rand();


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

    // Print CodeSum and CodeProduct to the terminal
    std::cout << "There are three numbers in the password\n";
    std::cout << "The numbers add up to: " << CodeSum << "\n";
    std::cout << "The numbers multiply to give: " << CodeProduct << "\n\n";

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

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

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


    // Check if player's guess is correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "Slug: \"You have guessed correctly! Wo!\"\n";
        std::cout << "Slug: \"Let's see how you handle the next password.\"\n";
        return true;
    }
    else
    {
        std::cout << "Slug: \"Yo dog, that is incorrect.\"\n";\
        std::cout << "Slug: \"Give it another trah!\"\n";
        return false;
    }
}


int main()
{
    int LevelDifficulty = 1;
    const int MaxLevelDifficulty = 8;
    while (LevelDifficulty <= MaxLevelDifficulty) // Loop game until all levels are complete
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear();
        std::cin.ignore();

        if (bLevelComplete)
        {
            // Increase the level difficulty
            ++LevelDifficulty;

        }
        
    }
    std::cout << "\n        ...                            \n";
    std::cout << "\nSlug: \"Just kidding! You did it man!\"\n";
    std::cout << "Slug: \"That's all the passwords.\"\n";
    std::cout << "Slug: \"Go on to the rest of yo life dude!\"\n";
    return 0;
}

1 Like

I was looking for this same solution. However, when I tried

if (Difficulty != MaxDifficulty && GuessSum == CodeSum && GuessProduct == CodeProduct)

I got a error saying the MaxDifficulty was an undeclared identifier. I am assuming it is because I declared it in the main(). So instead I used

if (Difficulty <= 4 && GuessSum == CodeSum && GuessProduct == CodeProduct)

That works but will be a problem if I decide to go in and change the number of levels.

Thanks for sharing your code.

I’m having an issue. Even if i win, my program will get out of the loop and return 0.

#include <iostream>

void PrintIntroduction(int Difficulty){
    if (Difficulty == 1)
    {
    std::cout << "\nYour submarine is the last standing in the open field with one battleships surrounding you.\n\n";
    //Ascii art
    std::cout << " _|_|_|_______\n(___________/\n\n\n\n                 ____||________\n                (_____________)\n\n";
    std::cout << "You need to input the right coordinates to destroy the battleship and survive...\n\n";
    }
    else{
    std::cout << "Your submarine is the last standing in the open field with some battleships surrounding you.\n\n";
    //Ascii art
    std::cout << " _|_|_|_______       _|_|_|________      _|_|_|________\n(___________/       (____________/      (____________/\n\n\n\n                 ____||________\n                (_____________)\n\n";
    std::cout << "You need to input the right coordinates to destroy the " << Difficulty <<  " battleships and survive...\n\n";
}
}

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


    int CoordinatesA = 4;
    int CoordinatesB = 2;
    int CoordinatesC = 6;
    int CoordinatesProduct = CoordinatesA*CoordinatesB*CoordinatesC;
    int CoordinatesSum = CoordinatesA+CoordinatesB+CoordinatesC;

        //print sum and the product
        std::cout << "There are three numbers in the panel.\n\nThe numbers multiply to give:\n";
        std::cout << CoordinatesProduct << std::endl;
        std::cout << "\nAnd the sum are:\n";
        std::cout << CoordinatesSum << std::endl;
        std::cout << "\nEnter the numbers.\n";

    int PlayerGuessA, PlayerGuessB, PlayerGuessC;

        //Store player guess
        std::cin >> PlayerGuessA >> PlayerGuessB >> PlayerGuessC;

        std::cout << "You entered: " << PlayerGuessA << ", " << PlayerGuessB << " and " << PlayerGuessC << ".";
    int GuessProduct = PlayerGuessA * PlayerGuessB * PlayerGuessC;
    int GuessSum = PlayerGuessA + PlayerGuessB + PlayerGuessC;

        std::cout << "\nThe product of your guesses is " << GuessProduct << "\n";        
        std::cout << "The sum of your guesses is " << GuessSum << "\n"; 

        //Condition to win
    if(GuessSum == CoordinatesSum && GuessProduct == CoordinatesProduct){
        std::cout << "\nYou survived.";
        return true;
    }
        else{
            std::cout << "\nYour submarine were destroyed and you died horribly.\n";
            return false;
        }

}



int main(){
    int LevelDifficulty = 1;
    int const MaxDifficulty = 5;
    while (LevelDifficulty <= MaxDifficulty) //Loop game until all levels are complete.
    {
    bool bLevelComplete = PlayGame(LevelDifficulty); 
            std::cin.clear(); //Clears any errors
            std::cin.ignore(); //Discard the buffer
        
        if (bLevelComplete)
        {
            ++LevelDifficulty;
            //increase the level dificulty
            }

    }
        


    return 0;
    }
1 Like


i am glad to understand what is going on.

1 Like

Great job!

#include

void PrintIntroduction(int Difficulty)
{
//this is an intergalactic puzzle game, this is the first message that is printed

std::cout << "\n\nPrincess Pluto needs your help infiltrating her enemy's palace, this is level: " << Difficulty;
std::cout << "\nFirst you need to prove yourself to continue... \n";

}

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

//declare the three variables for the code
const int CodeA = 2;
const int CodeB = 3;
const int CodeC = 4;

/* this is for
multiline 
comments 
cooooool */

//print the CodeSum and the CodeProduct for the code
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
std::cout << "\n";
std::cout << "There are three numbers in the code\n";
std::cout << "The Codes Add Up To:"<< CodeSum << "\n";
std::cout << "The Codes Multiply To Give You:"<<CodeProduct << "\n";

// store players guess
int  GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
std::cout << "You Entered:" <<GuessA << GuessB <<GuessC  <<"\n";

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

//check if player’s guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << “You are worthy, onward!” << “\n”;
return true;
}

else {
std::cout << “\nPrincess Pluto does not find you worthy, you will be sent home now and try again.”;
return false;
}
}

int main()
{

int LevelDifficulty = 1;
const int MaxLevel = 5;

while (LevelDifficulty <= MaxLevel) // loop game until all levels are complete

{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();

if (bLevelComplete)
{ 
   ++LevelDifficulty;
}

}

std::cout << “You have been knighted SOLDIER OF PLUTO, CONGRATULATIONS. LIVE LONG AND PROSPER!\n\n”;

 return 0;

}

#include <iostream>

void PrintIntroduction(int Difficulty)
{
    //STORY
    std::cout << "\n\nYou are a treasure hunter solving a category " << Difficulty << " case. The Mystery of King Solman's Mines...\n";
    std::cout << "Step on tiles in the correct sequence...\n\n";
}

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

    //VARIABLES
    const int SequenceA = rand();
    const int SequenceB = rand();
    const int SequenceC = rand();

    const int SequenceSum = SequenceA + SequenceB + SequenceC;
    const int SequenceProduct = SequenceA * SequenceB * SequenceC;

    //PRINT
    std::cout << "There are 3 tiles in this sequence.\n";
    std::cout << "These tiles add up to " << SequenceSum << "\n";
    std::cout << "These tiles multiply to give " << SequenceProduct << "\n";
    
    std::cout << "What is the sequence?\n";
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA;
    std::cin >> GuessB;
    std::cin >> GuessC;

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

    if (GuessSum == SequenceSum && GuessProduct == SequenceProduct)
    {
        std::cout << "You found the correct sequence!\n";
        return true;
    }
    else
    {
        std::cout << "You were eliminated by an arrow for stepping on the wrong tile.\n";
        return false;
    }
}

int main()
{
    int LevelDifficulty = 1;
    int const MaxLevelDifficulty = 3;

    while (LevelDifficulty <= MaxLevelDifficulty)
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear();
        std::cin.ignore();

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }
    std::cout << "Congratulations on winning the game! \n";
    return 0;
}

Thanks to @missing_pixel, I stole a few of your ideas with the --MaxTries.

#include <iostream>

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 << "Mix the " << Difficulty << "st Potion";
    }
    if(Difficulty == 2)
    {
        std::cout << "Mix the " << Difficulty << "nd Potion";
    }
    if (Difficulty == 3)
    {
        std::cout << "Mix the " << Difficulty << "rd Potion";
    }
    if (Difficulty != 1 && Difficulty != 2 && Difficulty !=3)
    {
        std::cout << "Mix the " << Difficulty << "th Potion";
    }
}

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 = 2;
    const int CodeB = 3;
    const int CodeC = 4;

    //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- 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()
{
    std::cout << "\nASCII GOES HERE.";

    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;
    int MaxTries = 5;

    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;
}
1 Like

This is my code so far :slight_smile:

#include <iostream>

int PrintIntroduction(int Difficulty)
{
    std::cout << "#############################################################################################################################################\n";
    std::cout << "##                                                                                                                                         ##\n";
    std::cout << "##   Hello and welcome to TripleX, an incredibly ingenious hacking game where fun is the name of the game. Well, not really but fuck it.   ##\n";
    std::cout << "##                                                                                                                                         ##\n";
    std::cout << "#############################################################################################################################################\n";
    std::cout << std::endl << "You're a secret agent breaking into LEVEL " << Difficulty << " secure server room.\n";
    std::cout << "Your SuperHacker 2000 tells you the following information...\n";

    return 0;
}

bool PlayGame(int Difficulty)
{
    // Print Outs
    PrintIntroduction(Difficulty);

    // Code numbers A, B and C
    const int CodeA = rand();
    const int CodeB = rand();
    const int CodeC = rand();
    
    // Sum and Mult variables
    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProd = CodeA * CodeB * CodeC;

    // Print out sum and mult
    std::cout << std::endl;
    std::cout << "There are three numbers in the code\n";
    std::cout << "The codes add-up to: " << CodeSum << std::endl;
    std::cout << "The codes multiply to give: " << CodeProd << std::endl;
    std::cout << std::endl;
    std::cout << "Enter the code followed by an X (# # # X): \n";

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

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

    // Check if player guess is correct
    if (GuessSum == CodeSum && GuessProd == CodeProd)
    {
        std::cout << "The code is correct!! Opening vault...\n" << std::endl;
        return true;
    } else {
        std::cout << "Your code is incorrect! Initiating alarm sequence...\n" << std::endl;
        return false;
    }

    std::cout << "#############################################################################################################################################\n";
    std::cout << "##                                                                                                                                         ##\n";
    std::cout << "##                                                            END OF GAME                                                                  ##\n";
    std::cout << "##                                                                                                                                         ##\n";
    std::cout << "#############################################################################################################################################\n";
}

int main()
{
    int LevelDifficulty = 1;
    const int MaxDifficulty = 7;

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

        if (LevelComplete)
        {
            // increase the level difficulty
            ++LevelDifficulty;
        }
    }

    std::cout << "#############################################################################################################################################\n";
    std::cout << "##                                                                                                                                         ##\n";
    std::cout << "##                                               CONGRATULATIONS, YOU BEAT THE GAME!! YAYYYY!!                                             ##\n";
    std::cout << "##                                                                                                                                         ##\n";
    std::cout << "#############################################################################################################################################\n";

    return 0;
}
1 Like

My game so far after the challenge in this lesson.
I just need to fix the dialogue during the level up a bit but otherwise it is working as it should.

#include <iostream>

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 
    int CodeA = 2;
    int CodeB = 4;
    int CodeC = 6;
    
    
    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";
        }
        else
        {
            Lifes--;
            if (Lifes == 0)
            {
                LoseGame();
                return 0;
            }
        }
        

               
    }
    
    //PlayGame();
    return 0;
}
2 Likes

Here’s how my Triple X Game is coming along - Just about to move onto the last part of Section 2. This has been a helpful refresher and reminder how to use C++ programming and how to use Visual Studio Code effectively in debugging and testing my game.
#include
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();
const int Code_B = rand();
const int Code_C = rand(); 

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() {

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;

}
Hope it seems legible so far.

Hello there :))

So far so good. Added new lines and updated if/else statements.

#include <iostream>

void PrintIntroduction(int Difficulty)
{ 
    // Print welcome messages to the terminal
    std::cout << "\n\nYou are kidnapped underground in the basement on the level " << Difficulty;
    std::cout << " \nYou need to enter the correct codes to escape...\n\n";
}

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

    // Declare 3 number code
    const int CodeA = 4;
    const int CodeB = 3;
    const int CodeC = 2;

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


    // Print CodeSum and CodeProduct to the terminal   
    std::cout << std::endl;
    std::cout << "+There are 3 numbers in the code";
    std::cout << "\n+The codes add-up to: " << CodeSum;
    std::cout << "\n+The code multiplied to: " << CodeProduct << 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 the player guess is correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "Correct code! Prepare for the next level...\n";  
        return true; 
    }
    else
    {
        std::cout << "Wrong code, retry again!\n";
        return false;
    }
}

int main()  
{
    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;
    while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels complted
    {
       bool bLevelComplete = PlayGame(LevelDifficulty);
       std::cin.clear(); //Clears any errors
       std::cin.ignore(); //Discards the buffer

       if (bLevelComplete)
       {   
           ++LevelDifficulty;
       }
       
    }

    return 0; 
}

2

Minor changes on where the Introduction function is called and the theme is, from one of my favorite shows I gotta say.

#include <iostream>

void PrintIntroduction()
{

    //Printing ASCII Art
    std::cout <<"\n\n ______    _      __    _  __\n";
    std::cout <<"/_  __/___(_)__  / /__ | |/_/\n";
    std::cout <<" / / / __/ / _ \\/ / -_)>  <  \n";
    std::cout <<"/_/ /_/ /_/ .__/_/\\__/_/|_|  \n";
    std::cout <<"         /_/                 \n";

    //Printing instructions
    std::cout << "Welcome to Numberwang!\n";
    std::cout << "To get numberwang, you need to guess the numbers that make the sum and the product that is given! \n\n";

}

bool PlayGame(int Difficulity)
{

    std::cout << "Round " << Difficulity;

    //Declaring the variables that are going to be used for the numbers
    int CodeA = rand() , CodeB = rand(), CodeC = rand();

    //Calculating the hints for the random numbers
    const int CodeSum = CodeA+CodeB+CodeC;
    const int CodeProduct = CodeA*CodeB*CodeC;
    
    //Printing the hints
    std::cout << std::endl << "- There are 3 numbers";
    std::cout << "\n- The sum of the digits is " << CodeSum; 
    std::cout << "\n- And the product of the numbers is " << CodeProduct << 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 whether the guess is correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\nThat's numberwang!";
        return true;
    } 
    else 
    {
        std::cout << "\nThat's not numberwang, You get another chance to guess";
        return false;
    }

}


int main()
{
    int LevelDifficulity = 1;
    const int MaxDifficulity = 10;

    PrintIntroduction();

    while (LevelDifficulity <= MaxDifficulity) //Loop until all levels are completed
    {
        bool bLevelComplete = PlayGame(LevelDifficulity);
        std::cin.clear(); //Clean error
        std::cin.ignore(); //Discard buffer

        if (bLevelComplete)
        {
            ++LevelDifficulity;
        }
        
    }

    std::cout << "\n\nCongratulations, you are this weeks Numberwang champion!";

    return 0;
}
1 Like

hehe, this is what i got so far…pretty excited so far :slight_smile:

#include <iostream>   // preprocessor directive

void PrintIntroduction(int Difficulty)
{    //start of the program
    std::cout << "\n\n#####   You are a secret agent breaking into ACME LABS. #####\n";
    std::cout << "#####   You're at the server room on Level " << Difficulty;
    std::cout << " , but seems to be code secured #####\n";
    std::cout << "Please enter the correct code to continue ....\n\n";
    std::cout << "-------------------------\n";
    std::cout << "|       |  ABC  |  DEF  |\n";
    std::cout << "|   1   |   2   |   3   |\n";
    std::cout << "-------------------------\n";
    std::cout << "|  GHI  |  JKL  |  MNO  |\n";
    std::cout << "|   4   |   5   |   6   |\n";
    std::cout << "-------------------------\n";
    std::cout << "| PQRS  |  TUV  | WXYZ  |\n";
    std::cout << "|   7   |   8   |   9   |\n";
    std::cout << "-------------------------\n";
    std::cout << "|       |       |       |\n";
    std::cout << "|   *   |   0   |   #   |\n";
    std::cout << "-------------------------\n";
}

bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);
    
    //declaring initial 3 number codes
    const int CodeA = rand(); // values of a using const that means it cannot be changed
    const int CodeB = rand(); 
    const int CodeC = rand();
    int GuessSum;
    int GuessProduct;

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

    //print the sum and product values to stdout
    std::cout << std::endl;
    std::cout << "* There are 3 numbers in the code\n";
    std::cout << "\n* The codes add up to: " << CodeSum;
    std::cout << "\n* The product or combined value of the 3 numbers add up to: " << CodeProduct;

    // get input from user and store it
    int GuessA, GuessB, GuessC;
    std::cout << "\nCode Please....\n";
    std::cin >> GuessA;
    std::cin >> GuessB;
    std::cin >> GuessC;

    // calculate the sum & total val
    GuessSum = GuessA + GuessB + GuessC;
    GuessProduct = GuessA * GuessB * GuessC;

    // compare if the guessed value is the same as the initial values
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\nCongrats, \"you WIN!\"";
        return true;
    }
    else
    {
        std::cout << "\nYou guessed incorrectly, You DIE!";
        return false;
    }
}

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

        if (bLevelComplete)
        // increase level difficulty if true
        {
            ++LevelDifficulty;
        }
        
    }
    std::cout << "Congratulations, you are a Master Burglar!\n";
    return 0;
}
2 Likes

This is the progress I have made in my TripleX.

Game3

1 Like

Here is my code so far.

#include<iostream>
#include<chrono>
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();
    const int CodeB = rand();
    const int CodeC = rand();

    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 ()
{
    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;
}
1 Like

Privacy & Terms