Just finished making my version of the TripleX game. Had a lot of fun learning and was very easy to understand.
void PrintIntroduction(int Difficulty)
{
// Prints out the intro message
std::cout << std::endl;
std::cout << “Welcome Detective Jackie, the entire building complex is under my control.\n”;
std::cout << “If you wanna catch me you better clear each floor without me knowing.\n”;
std::cout << “Cause’ if I catch you in the terminal, it will be all over for you Detective.\n”;
std::cout << std::endl;
std::cout << "Current floor security level " << Difficulty;
std::cout << std::endl;
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
// Declares the variables
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 CodeMultiply = CodeA * CodeB * CodeC;
// Prints out values of "CodeSum" and "CodeMultiply"
std::cout << std::endl;
// std::cout << CodeA << CodeB << CodeC << std::endl; // Only to see the randomized values
std::cout << "\n* There are three numbers in the code";
std::cout << "\n* The codes add-up to: " << CodeSum;
std::cout << "\n* The codes multiply to: " << CodeMultiply <<std::endl;
// Store player guess values
int GuessA, GuessB, GuessC;
std::cout << std::endl;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessMultiply = GuessA * GuessB * GuessC;
// Print out win or lose statement
if(CodeSum == GuessSum && CodeMultiply == GuessMultiply)
{
std::cout << "\n*** Override code accepted, current building level unsealed, rebooting local security system. ***\n";
return true;
}
else
{
std::cout << "\n*** I found you detective, should have guessed better, releasing the neuro toxins ***\n";
return false;
}
}
int main()
{
srand(time(NULL));
int LevelDiffuculty = 1;
int const MaxLevel = 7;
while (LevelDiffuculty <= MaxLevel) //Loop game until all levels are completed
{
bool bLevelComplete = PlayGame(LevelDiffuculty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
{
++LevelDiffuculty;
}
}
std::cout << "\n*** Looks like you caught me detective. Congrats. ***\n";
return 0;
}