How is your Triple X game looking?

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
#include <iostream>

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 = 4;
    const int CodeDigitB = 8;
    const int CodeDigitC = 2;

    // Hint for player to decipher code in form of multiplication and addition. 
    //MUST BE CHANGED IF NOT REQUIRED FOR TRAINING PROGRESSION.
    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 (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;
        } 
        /* 
            else if (Difficulty == 10)
        {
            std::cout << "System overide succesful proceed to enter hab ring.";
        }
        */
}
int main ()
{
    int LevelDifficulty = 1;
    const int MaxLevelDifficulty = 5;

    //Loops game until level 10 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

My game is about bitwise operators :smile:
Also i use the c++11 way to generate the random number

#include <iostream>
#include <random>

void PrintIntroduction(const int&);
bool PlayGame(const int&);

int main()
{
  bool bLevelComplete;
  int LevelDifficulty = 1;
  const int MaxDifficulty = 5;

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

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

  }

  std::cout << "***you've decode all message, now you know everything***";
  std::cout << std::endl;

  return 0;
}

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

  int Mask = 0xf << (4 * (Difficulty - 1));
  std::random_device RandomDevice;
  std::mt19937 MersenneTwister(RandomDevice());
  std::uniform_int_distribution<> IntDist(0, Mask);
  const int Message = IntDist(MersenneTwister);
  

  int Complement = Message ^ Mask;
  std::cout << "+ The message is: " << Message << std::endl;
  std::cout << "+ The disguise is: " << Mask << std::endl << std::endl;

  int PlayerGuess;
  std::cin >> PlayerGuess;

  bool result = false;
  if (Complement == PlayerGuess)
  {
    result = true;
    std::cout << "You decode The message, for now you still alive" << std::endl;
  }
  else
  {
    std::cout << std::endl;
    std::cout << "++You died cause you didn't know the message++" << std::endl;
    std::cout << "++Try Again++" << std::endl;
  }

  std::cout << std::endl;

  return result;

  Mask << 4;
  Mask += 0xf;
}

void PrintIntroduction(const int& Difficulty)
{
  std::cout << "You are a secret agent decoding a level " << Difficulty;
  std::cout << " secrect message..." << std::endl;
  std::cout << "Enter the correct code to continue...";
  std::cout << std::endl << std::endl;
}
1 Like

Really good am learning alot

1 Like

Haven’t introduced that satisfying ASCII art just yet, yet, here wo go with the code:

Untitled5

Untitled6

There we go,
Thanks a lot,

-Vlad.

1 Like

1 Like

I love the bomb art!

1 Like

using namespace std;
#include <iostream>

void PrintIntroduction(int Difficulty, int MaxDiff) {
    std::cout<<"You are in prison, your objective is to escape Through the ";
    cout << MaxDiff<< " Locked doors...\n";
    cout << "You are now in door " << Difficulty << endl;
    }

bool PlayGame(int Difficulty, int MaxDiff){
     //code for a prison escape game
    PrintIntroduction(Difficulty, MaxDiff);

    const int CodeA = 10;
    const int CodeB = 15;
    const int CodeC = 5;

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


    cout << "\n\nLooking at the lookscreen you notice it you notice the securities use a 3 pin lock, \n";
    cout << "The codes add up to: " << CodeSum << endl;
    cout << "The codes multiplied give: " << CodeProduct<< endl;

    int GuessA, GuessB,GuessC;
    cout << "Enter guess here: ";
    cin >> GuessA >> GuessB >> GuessC;
    

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

    //checks if user guess is correct or not
    if (GuessSum == CodeSum && GuessProduct == CodeProduct){
        cout << "\n\nDoor gently opens up for you!! " << MaxDiff - Difficulty << " more doors to go.\n\n";
        return true;
    } else {
        cout << "\n\nSecurity alarm goes off, wrong pin entered. keep trying!\n\n";
        return false;
    }
}


int main(){
    int levelDiff = 1;
    int maxDiff = 5;

    while (levelDiff <= maxDiff)
    {
        bool bLevelComplete = PlayGame(levelDiff,maxDiff);
        cin.clear();
        cin.ignore();

        if (bLevelComplete)
        {
          ++levelDiff;
        }
      
    }
    
   cout << "Well done Agent 47, You have passed your first assignment!!!";


    return 0;
}

My game code so far. I have changed a few things including counting down in the while loop rather than up as it suits my game scenario better. I also pause the program after each entry response, so it’s easier to read it. So far so good

// TripleX game to demonstrate some fundamentals of a simple C++ program

// Preprocessor Directives - instructions to the compiler
#include <iostream>   // header file for input output stream functionality

// Our PrintIntroduction function
void PrintIntroduction(int NumOfPortals)
{
	// Expression statements
	std::cout << "You have been teleported through " << NumOfPortals << " rooms with seemingly\n";  // std is a namespace, :: is a scope operator, << is an insertion operator which inserts chrs into the output stream
	std::cout << "no way out other than back through the portals themselves.\n" ; // \n (escape sequence) starts a new line, you could have used << std::endl at the end of the line instead
	std::cout << "The portal devices have deactivated but each appear to have\n";
	std::cout << "a numeric keypad requiring a numeric input to activate them.\n\n";
}

// Our PlayGame function
bool PlayGame(int NumOfPortals, int CurrentPortalNum, bool bIntroDisplayed)  // void is used here as the return type as there is no return data in this function
{
	if (not bIntroDisplayed)
	{
		PrintIntroduction(NumOfPortals);
	}
		
	std::cout << "Number of portals remaining: " << CurrentPortalNum << "\n\n";

	// Variable declarations - Note the naming convention used by Unreal Engine (UpperCase letter for each word with no underscores)
	const int NumA = 4;  // Initialised to 4 using the equals assignment operator, Const ensures that the variable cannot be changed after it's been declared and initialised
	const int NumB = 3;  // Initialised to 3
	const int NumC = 2;  // Initialised to 2

	const int NumSum = NumA + NumB + NumC;  // Use of the arithmetic operator +
	const int NumProduct = NumA * NumB * NumC;

	// Expression statements
	std::cout << "Your concealed hacking tool reveals portal " << CurrentPortalNum << " requires three key\n";
	std::cout << "numbers to be entered in any order, along with the following\n";
	std::cout << "information:\n";
	std::cout << "Their numbers add up to: " << NumSum;
	std::cout << "\nTheir numbers multiply to give: " << NumProduct;
	std::cout << "\n\nEnter the correct 3 numbers (in any order) to escape back\n";
	std::cout << "through portal " << CurrentPortalNum << " (leave a space between each number) ...\n";

	int GuessA;
	int GuessB;
	int GuessC;
	int GuessSum;
	int GuessProduct;

	// Get player input
	std::cin >> GuessA >> GuessB >> GuessC;  // cin captures player kbd input, >> << is an extraction operator which extracts chrs from the input stream 

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

	if (GuessSum == NumSum && GuessProduct == NumProduct)  //  == is the equality operator (comparison operator), && is the boolean AND operator
	{
		std::cout << "\nThe portal flashes briefly then bursts into life. You get to\n";
		std::cout << "step through the portal :-)\n\n";
		return true;
	}
	else
	{
		std::cout << "\nThe portal remains lifeless.  Looks like you need to try \n";
		std::cout << "again.\n\n";
		return false;
	}
}


// main function
int main() 
{ 
	int NumOfPortals = 5;
	int CurrentPortalNum = NumOfPortals;
	bool bIntroDisplayed = false;

	// Loop game until all levels completed
	while (CurrentPortalNum > 0)
	{
		bool bLevelComplete = PlayGame(NumOfPortals, CurrentPortalNum, bIntroDisplayed);  // Unreal naming convention has bool variables prefixed with a lower base b

		bIntroDisplayed = true;

		std::cin.clear();  // Clears the error status flags
		std::cin.ignore(256, '\n'); // removes all characters in the stream buffer up to the new line 256, '\n'

		std::cout << "Press Enter key to continue\n";
		std::cin.get();

		if (bLevelComplete)
		{
			--CurrentPortalNum;
		}
	}
	
	std::cout << "You stumble out of the final portal back into the room you\n";
	std::cout << "started from.  Congratulations!!!\n\n\n";
	
	// Return statement
	return 0; 
}

Example output:

You have been teleported through 5 rooms with seemingly
no way out other than back through the portals themselves.
The portal devices have deactivated but each appear to have
a numeric keypad requiring a numeric input to activate them.

Number of portals remaining: 5

Your concealed hacking tool reveals portal 5 requires three key
numbers to be entered in any order, along with the following
information:
Their numbers add up to: 9
Their numbers multiply to give: 24

Enter the correct 3 numbers (in any order) to escape back
through portal 5 (leave a space between each number) …
2 3 4

The portal flashes briefly then bursts into life. You get to
step through the portal :slight_smile:

Press Enter key to continue

Number of portals remaining: 4

Your concealed hacking tool reveals portal 4 requires three key
numbers to be entered in any order, along with the following
information:
Their numbers add up to: 9
Their numbers multiply to give: 24

Enter the correct 3 numbers (in any order) to escape back
through portal 4 (leave a space between each number) …
1 2 3

The portal remains lifeless. Looks like you need to try
again.

Press Enter key to continue

The game ends if you get the code wrong but then gives the option to replay.
Also added some text color and user input error checking for the replay game input.

#include <iostream>
#include <windows.h>

void PrintIntroduction()
{
    // Set font to green
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 10);

    // Print game title to console
    std::cout << "\n\n";
    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";

    // Set font to white
    SetConsoleTextAttribute(hConsole, 15);

    // Print welcome message to console
    std::cout << "\n\nYou are a newbie hacker, making a name for youself by beaking into a high profile server!\n";
    std::cout << "There are 10 levels of encryption you must bypass in order to access the server root.\n";
    std::cout << "Each encryption level requires a specic code sequqnce to be entered.\n\n";
}


bool PlayGame(int Difficulty)
{
    PrintIntroduction();
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    
    // Declare 3 numbr code
    const int CodeA = 4;
    const int CodeB = 6;
    const int CodeC = 9;

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

    // Set colour for Encryiption level output
    int Colour; // 5 levels
    switch(Difficulty)
    {
        case 1 : Colour = 15; // White
        break;

        case 2 : Colour = 11; // Light Blue
        break;

        case 3 : Colour = 14; // Yellow
        break;

        case 4 : Colour = 13; // Pink
        break;

        case 5 : Colour = 12; // Red
        break;

    }

    if (Difficulty > 1)
    {
        std::cout << "Well Done! Proceed to crack the next level of encryption... \n\n";
    }

    SetConsoleTextAttribute(hConsole, Colour);

    // Write Ecryption elvel to the console
    std::cout << "*** ENCRYPTION LEVEL " << Difficulty << " ***\n\n";

    // Set font back to white
    SetConsoleTextAttribute(hConsole, 15);

    // Print CodeSum and CodeProduct to the termainal
    std::cout << "+ Thre are three numbers in the code.\n";
    std::cout << "+ The codes add up to: " << CodeSum << "\n";
    std::cout << "+ The codes multiply to give: " << CodeProduct << "\n\n";
    
    std::cout << "You need to enter the correct codes to continue...\n";

    // Store player guess 
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;
 
    // Deelcare and initalise GuessSum and GuessProduct
    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    // Check GuessSum and GuessProduct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
            return true;
    }
    else
    {
            return false;
    }
}


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

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

        if (bLevelComplete) 
        {
            ++LevelDifficulty;
        }
        else {
            std::cout << "\nYour crack attempt failed and your IP has been traced. Killer drones are on their way to your house...\n\n";
            std::cout << "Would you like to play again?... (y/n)\n";

            bool ReplayAnswer = false;
            std::string ReplayGameAnswer;


            while(!ReplayAnswer)
            {
                // Get y or n from player
                std::cin >> ReplayGameAnswer;
                std::cin.clear(); // CLears any errors
                std::cin.ignore();

                if (ReplayGameAnswer == "y" || ReplayGameAnswer == "Y" || ReplayGameAnswer == "n" || ReplayGameAnswer == "N")
                {
                    ReplayAnswer = true;
                }
                else 
                {
                    ReplayAnswer = false;
                    std::cout << "Incorrect syntax. Please enter y or n...\n";
                }
            }

            if (ReplayGameAnswer == "y" || ReplayGameAnswer == "Y")
            {
                LevelDifficulty = 1;
                //PlayGame(LevelDifficulty);
            } 
            else{
                std::cout << "\n*** GAME OVER ***\n";
                return 0;
            }

        }
    }
    
    std::cout << "\nYou have cracked the encryption and now have root access to the server. HAZ GOT MAD SKILLZ!!!\n";
    return 0;
}