How is your Triple X game looking?

hi all,

My mess so far… :sweat_smile:

#include <iostream>
#include <string>

using namespace std;

bool PlayGame(const short int& LevelDifficulty);
void PrintIntro(const short int& LevelDifficulty);
void PrintHint(const short int& CodeSum, const short int& CodeProduct);
bool CheckInput(string& Input);

int main()
{
	short int LevelDifficulty{ 1 };
	const char MaxDifficulty{ 4 };

	while (LevelDifficulty <= MaxDifficulty)
	{		
		//PlayGame();
		bool bLevelComplete = PlayGame(LevelDifficulty);
		
		//Increase difficulty or close.
		if (bLevelComplete)
		{
			LevelDifficulty++;
			cout << "\nComputer hacked!\nMoving to next level.\n\n";
		}
		else
		{
			LevelDifficulty = 1;
		}

	}// while
	
	cout << "\nSYSTEM HACKED..\n";

	return 0;
}

bool PlayGame(const short int& LevelDifficulty)
{
	// Declate three number code.
	const char ThreeNumberCode[3]{ 2, 2, 2 };
	const short int CodeSum{ ThreeNumberCode[0] + ThreeNumberCode[1] + ThreeNumberCode[2] };
	const short int CodeProduct{ ThreeNumberCode[0] * ThreeNumberCode[1] * ThreeNumberCode[2] };

	// Storew players input
	short int PlayersGuess[3]{};
	short int PlayersGuessSum{ 0 };
	short int PlayersGuessProduct{ 0 };

	PrintIntro(LevelDifficulty);
	PrintHint(CodeSum, CodeProduct);
	
	string Input;
	cout << "\nEnter the correct code: ";
	getline(cin, Input);

	if (!CheckInput(Input))
	{
		cout << "Input is not valid.\n";
		return false;
	}
	else
	{
		char SpaceFound{ 0 };

		if(Input.find(' ') != string::npos)
			PlayersGuess[0] = stoi(Input.substr(0, Input.find(' ')));

		SpaceFound = Input.find(' ') + 1;

		if (Input.find(' ', 1) != string::npos)
			PlayersGuess[1] = stoi(Input.substr(SpaceFound, Input.find(' ', 1)));
		
		SpaceFound = Input.find(' ', SpaceFound);

		PlayersGuess[2] = stoi(Input.substr(SpaceFound, Input.size() - 1));

		Input.clear();

		PlayersGuessSum = PlayersGuess[0] + PlayersGuess[1] + PlayersGuess[2];
		PlayersGuessProduct = PlayersGuess[0] * PlayersGuess[1] * PlayersGuess[2];

		if (PlayersGuessProduct == CodeProduct && PlayersGuessSum == CodeSum)
		{
			return true;
		}
		else
		{
			cout << "\nERROR: WRONG CODE.. RESTARING.\n\n";			
		} // PlayGame.. if else.. if else
		return false;
	}// PlayGame.. if else
}// PlayGame
void PrintIntro(const short int& LevelDifficulty)
{
	if (LevelDifficulty == 1)
		cout << "You are a secret agent breaking into a secure server room.\n";

	cout << "Enter the correct code to continue...\n";
	cout << "Level Difficulty: " << LevelDifficulty << '\n';
}
void PrintHint(const short int& CodeSum, const short int& CodeProduct)
{
	cout << "There are three numbers in the code.\n";
	cout << "The code add-up to: " << CodeSum << '\n';
	cout << "The code multiply to get: " << CodeProduct << '\n';
}// PrintHint
bool CheckInput(string& Input)
{
	int SpaceCount{ 0 };

	for (int i = 0; i < Input.size(); i++)
	{
		if (!isdigit(Input[i]) && Input[i] != ' ')
			return false;
		if (Input[i] == ' ')
			SpaceCount++;
	}// CheckInput.. for

	if (SpaceCount == 2)
		return true;
	else
		return false;
}// CheckInput

How I imagine Triple X these days :slight_smile:

#include <iostream>


void PrintIntroduction(int Difficulty, int MaxLevel)
{
//Print Rules to terminal
    std::cout << "\n\nYou are the Provencial Health Officer of British Columbia, and were requested by journalists to give an update on Covid for " << MaxLevel <<" weeks in a row.\n";
    std::cout << "This is week nr " << Difficulty <<".\n";
    std::cout << "Give today's quantity of new covid cases to continue...\n";
}

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


    //Declare 3 number code
    const int CodeA = 4;
    const int CodeB = 5;
    const int CodeC = 8;
    
    /*
    This is a multiline comment
    */

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

// Print sum and product to terminal
    std::cout << "\n+ The amount is made of 3 numbers...\n\n";
    std::cout << "+ The quantity of Covid cases add up to: " << CodeSum << "\n";
    std::cout << "+ The quantity of Covid cases makes " << CodeProduct << " if multiplied." << 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 player guess is correct
        if(GuessSum == CodeSum && GuessProduct == CodeProduct )
        {
            if(Difficulty != MaxLevel)
            {
                std::cout << "You have read properly the scientists data and indicated the right quantity. Another " << MaxLevel - Difficulty << " weeks to go !";
            }
            return true;
        }
        else
        {
            std::cout << "More Antivax are rioting in the street as they could find proofs that wrong numbers were given on flatearthers.com ... Better be more careful next time if we want to finish the "<< MaxLevel << "successful weeks assignment...";
            return false;
        }
}

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

    if(bLevelComplete) 
    {
        ++LevelDifficulty;
    }
    }

    std::cout << "Well done, you have outdone yourself ! Canada is proud of you... The Queen (or just Harry), will come congratulate you.";
    return 0;
}

My triplex version so far

#include <iostream> //This is the preprocessor directive

void PrintIntroduction(int Difficulty)
{
    //Print welcome message of the game in the terminal
    std::cout << "\n --- You need to solve the equation that will allow you to merge the ancient runes into the core of your level " << Difficulty << " gadget --- \n";
    std::cout << "\n --- So now you have to write down the correct numbers, in order to solve the equation --- \n"; 

}

//Making our own function
bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);

    //Declaration of the 3 numbers of the code and the sum and product
    const int CodeA = 2;
    const int CodeB = 4;
    const int CodeC = 6;

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

    //Printing sum and product to the terminal
    std::cout << "\n+ There are three numbers in the equation\n";
    std::cout << "+ The three numbers add-up to: " << CodeSum << std::endl;
    std::cout << "+ The three numbers multiply to give: " << CodeProduct << std::endl;

    //Getting the guess from the player and storing it
    int GuessA, GuessB, GuessC; 
    std::cout << "\nPlease type your first guess\n";
    std::cin >> GuessA;
    std::cout << "Please type your second guess\n";
    std::cin >> GuessB;
    std::cout << "Please type your third guess\n";
    std::cin >> GuessC;

    //Sum and product with the guessed values
    const int GuessSum = GuessA + GuessB + GuessC;
    const int GuessProduct = GuessA * GuessB * GuessC;

    //if else statement to see if the player is correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\n --- The runes stabilize and your gadget's core merges with them, congratulations, you have succeed on this one! --- \n";
        std::cout << "\n --- But there are more gadgets waiting for you, so you are going to try with a gadget a little more complex --- \n";
        return true;
    }
    else
    {
        std::cout << "\n --- The runes reject the gadget making it burn in magic fire, and causing a shortcircuit in your laboratory! --- \n";
        std::cout << "\n --- You failed in this ocassion, but as the alchemists say, you can't make a philosopers stone without breaking some flasks --- \n";
        std::cout << "\n --- You clean the laboratory and prepare a replica of the same gadget to continue working --- \n";
        return false;
    }    
}

int main()
{
    int LevelDifficulty = 1; //variable for the level of difficulty
    const int MaxLevel = 5; //Variable for the total of levels

    std::cout << "\n --- You are not a mage neither a scientist, you found your way in the path between those, you are an alchemist! --- \n";
    std::cout << "\n --- You have dedicated your lifework into combining the ancient magic runes with the more advanced techonology --- \n";

    while (LevelDifficulty <= MaxLevel) //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)
        {
            // Increasing the level difficulty 
            ++ LevelDifficulty;
        }
        
    }
    std::cout << "\n --- You successfully merged the ancient runes into the core of all your gadgets, you will always be remember as the greatest of all alchemist --- \n";
    std::cout << "\n --- Congratulations!!! --- \n";
    return 0;
}
#include <iostream> 
/*
This code gives the user an info about three numbers 
and user tries to guess them.
*/

void PrintIntrodiction(int Diff)
{
    //Welcomes the user and describes the lore
    std::cout << "\nYour father said that he's going to market to buy a milk...\n";
    std::cout << "...but he never came back. One day, you got an e-mail that says\"Your Father is here.\"\n";
    std::cout << "U went to the adress given in the email and see some password doors. Good luck solving them!\n";
    std::cout << "_______________________________________________________________________________________________\n\n";
    std::cout << "Level:"<< Diff << "...\n";
}   


bool PlayGame(int Diff)
{
    PrintIntrodiction(Diff);
    //Declare 3 number code
    
    const int CodeA = 2;
    const int CodeB = 3;
    int CodeC = 4;
    
    int CodeSum = CodeA + CodeB + CodeC;
    int CodeProduct = CodeA * CodeB * CodeC;

    //Print sum and product (prd) to the terminal.

    std::cout << "+Each door has 3 numbers and you need to guess them.\n";
    std::cout << "+Sum of them: " << CodeSum<< "\n";
    std::cout << "+Product of them: "<< CodeProduct << "\n";  
    //Player guesses numbers
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;
    std::cout << "\n";
    std::cout <<"Your guess is: " <<GuessA<<", "<<GuessB<<" and "<<GuessC; 

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;
    //Checks if the guessed numbers and the code numbers are the same.
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\n\nCorrect! Moving on to the next door.";
        return true;
    }
    else 
    {
        std::cout << "\n\nWrong! Try again! :(\n";
        return false;   
    }
}

int main() 
{   
    int Level = 1;
    const int MaxLvl = 5;
    
    while(MaxLvl > Level)
    {
        bool bLevelComplete = PlayGame(Level);
        std::cin.clear();
        std::cin.ignore();

        if (bLevelComplete)
        {
            ++Level;
        }
    } 
    std::cout << "Congrats! You find your dad and have some milk together. \n\nTHE END";
    return 0;
}```

Hi Everyone, Here is my code just prior to randomising the numbers. Almost there!

#include <iostream>

void PrintIntroduction(int Difficulty)
{
    //  Initial Message and setting of scene
    std::cout << std::endl;
    std::cout << R"(                _)" << std::endl;                            
    std::cout << R"(               | |)" << std::endl;                           
    std::cout << R"(  ___ _ __   __| | __ _  __ _ _ __ ___   ___ )" << std::endl; 
    std::cout << R"( / _ \ '_ \ / _` |/ _` |/ _` | '_ ` _ \ / _ \)" << std::endl; 
    std::cout << R"(|  __/ | | | (_| | (_| | (_| | | | | | |  __/)" << std::endl; 
    std::cout << R"( \___|_| |_|\__,_|\__, |\__,_|_| |_| |_|\___|)" << std::endl; 
    std::cout << R"(                   __/ |               )" << std::endl;       
    std::cout << R"(                  |___/                      )" << std::endl; 
    std::cout << "\n\nWelcome to the endgame, Level " << Difficulty ;
    std::cout << ".\n\n";
    std::cout << "The hordes are approaching, their unruly, riotous yelping can be heard all around.\n";
    std::cout << "You have found a handgun that appears to have been locked electronically.\n\n";
    std::cout << "You must enter the correct three digit code to unlock the weapon.....\n";
}

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

    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 and product to terminal
    std::cout << "\nThere are 3 numbers in the code\n";
    std::cout << "The codes add up to: " << CodeSum;
    std::cout << "\nThe codes product equals: " << CodeProduct;
    std::cout << "\n\nPlease enter your guess (Numbers Only!) seperated by a space and then press Enter\n\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 Players Guess is correct
    if  (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\nCongratulations, you have guessed correctly and unlocked the power of the handgun.\n";
        std::cout << "The Hordes fall at your feet!\n";
        std::cout << "\nYou have progressed to the next level.\n";
        return true;
    }
        else
    {
        std::cout << "\nOh No!! The code you entered was incorrect, Try Again!!\n";
        return false;
    }
}

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

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

    if (bLevelComplete)
    {
        ++LevelDifficulty;
    }
    }
   
   std::cout << "\n Congratulations! You have conquered all 5 Levels of the Endgame";
   std::cout <<"\n You truly are unstoppable!";

   return 0;    
}


Thanks for the information!




so its nearly as awesome as I would want it to be :joy: will fix few things in looks after randomiser


and just fixing some looks before that crazy 32767 gets into the game !)

Privacy & Terms