TripleX2021

Doing this as a refresher with the updated material. Here is my code for the new tripleX game with ASCII art.

#include <iostream>
#include <ctime>

void Intro(int Difficulty)
{
	std::cout << R"(
	         _________________________.
	        / _____________________  /|
	       / / ___________________/ / |
	      / / /| |               / /  |
	     / / / | |              / / . |
	    / / /| | |             / / /| |
	   / / / | | |            / / / | |
	  / / /  | | |           / / /| | |
	 / /_/___| | |__________/ / / | | |
	/________| | |___________/ /  | | |
	| _______| | |__________ | |  | | |
	| | |    | | |_________| | |__| | |
	| | |    | |___________| | |____| |
	| | |   / / ___________| | |_  / /
	| | |  / / /           | | |/ / /
	| | | / / /            | | | / /
	| | |/ / /             | | |/ /
	| | | / /              | | ' /
	| | |/_/_______________| |  /
	| |____________________| | /
	|________________________|/


	)" << '\n';
	std::cout << "Hello, Console Cowboy, are you ready to crack the level " << Difficulty;
	std::cout << " black ice of Hosaka?...\nEnter the correct code to continue...\n\n";
}
bool PlayGame(int Difficulty)
{
	

	Intro(Difficulty);

	
	const int Codea = rand() % Difficulty + Difficulty;
	const int Codeb = rand() % Difficulty + Difficulty;
	const int Codec = rand() % Difficulty + Difficulty;



	const int codesum = Codea + Codeb + Codec;
	const int codeproduct = Codea * Codeb * Codec;

	std::cout << std::endl;
	std::cout << "+ There are three numbers in the code";
	std::cout << "\n+ The codes add up to: " << codesum;
	std::cout << "\n+ The codes multiply to give: " << codeproduct << std::endl;

	//Stores players guess
	int GuessA, GuessB, GuessC;
	std::cin >> GuessA >> GuessB >> GuessC;

	//std::cout << "You guessed: " << GuessA << GuessB << GuessC;

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


	//Checks if the player guess matches code
	if (GuessSum == codesum && GuessProduct == codeproduct)
	{
		std::cout << "\nYou have cracked level " << Difficulty << " of the black ice.";
		return true;
		
	}
	else
	{
		std::cout << "\n****You have entered the wrong code. The ice is closing in. \nPlease try Again...";
		return false;
	}
}

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

	
	
	while(LevelDifficulty <= MaxDifficulty) //Loops the game while 
	{
		bool bLevelComplete = PlayGame(LevelDifficulty);
		std::cin.clear(); //Clears any errors
		std::cin.ignore(); // Discards the Buffer

		if(bLevelComplete)
		{
			++LevelDifficulty;//Increase Level difficulty
		}
	}
	std::cout << "\n****Great work cowboy. You have cracked all of the ice! Get the data and run like hell!";
	
    return 0;
}
1 Like

Thanks for sharing. I like it. The cube is so confusing it’s perfect for this.

1 Like

Privacy & Terms