Hi everyone! Here’s my version of TripleX. As the number of retries increases, the weathered statue taunts you more… (excuse the mild language):
#include <iostream>
#include <ctime>
void PrintIntroduction(int Difficulty, int Retries)
{
std::cout << "\n\nYou are in an ancient level " << Difficulty << " dungeon and encounter a weathered statue...\n";
if (Retries == 0)
{
std::cout << "It suddenly says, to you, \"Oyy there, who said you could pass?\"\n";
std::cout << "\nYou stare at it in surprise...\n";
std::cout << "It looks down then stares right back at you...\n";
std::cout << "\n\"Oyyy! What you lookin' at chump?\n";
std::cout << "\"Say the code already...\n";
}
else if (Retries == 1)
{
std::cout << "It suddenly says, to you, \"Oyy there, who said you could pass?\"\n";
std::cout << "\nYou stare at it. This looks familiar...\n";
std::cout << "It looks up then stares right back...\n";
std::cout << "\n\"Oyyy! What you lookin' at chump?\n";
std::cout << "\"Say the code already...\n";
}
else if (Retries == 2)
{
std::cout << "You slap yourself on the face.\n";
std::cout << "It reaches out and slaps you back.\n";
std::cout << "You stare at it in shock...\n";
std::cout << "\n\"Oyyy! What you lookin' at chump?\n";
std::cout << "\"Say the code already...\n";
}
else if (Retries == 3)
{
std::cout << "You think, 'Oh my...'\n";
std::cout << "\"Oh my what? Stupid! Can't guess a silly nilly code?\n";
std::cout << "\n\"Come now...\n";
}
else
{
int Taunt = rand() % 3;
if (Taunt == 0)
{
std::cout << "You slap yourself again.\n";
std::cout << "\"Oyy! You think that will help?\"\n";
std::cout << "It reaches out...\n";
std::cout << "\n*SLAP*\n";
}
else if (Taunt == 1)
{
std::cout << "\"Oyy, fleshling! My brain's made of stone and I think better than you!\"\n";
std::cout << "You feel like puking...\n";
std::cout << "\n\"Pfft. HAHAHAHA!\n";
}
else
{
std::cout << "It looks disappointed...\n";
std::cout << "VERY DISAPPOINTED.\n";
std::cout << "\n\"Oyy, for real now...\n";
}
}
}
bool PlayGame(int Difficulty, int Retries)
{
PrintIntroduction(Difficulty, Retries);
// Declare secret codes, sum and product
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;
// Statue gives player the hint
std::cout << "\"It adds up to " << CodeSum << ".\n";
std::cout << "\"It gives ya " << CodeProduct << " when multiplied together.\"\n";
// Store player guess
int GuessA, GuessB, GuessC;
std::cout << "\nYou think:\n";
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// Check if the player's guess is correct
std::cout << "\nThe statue raises its head, \"Hmm... '" << GuessA << " " << GuessB << " " << GuessC << "' you say?\"\n";
std::cout << "\"I never...\"\n";
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\"Yip, you got the code! You may pass.\"\n\n";
return true;
}
else
{
std::cout << "\"You think what you say, and say what you think, right?\n";
std::cout << "\"Dumb ass, you are wrong! Bye bye.\"\n\n";
return false;
}
}
int main()
{
srand(time(NULL)); // Create new random sequence based on time of day
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
int NumberOfRetries = 0;
while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels completed
{
bool bLevelComplete = PlayGame(LevelDifficulty, NumberOfRetries);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
NumberOfRetries = 0;
} else {
++NumberOfRetries;
}
}
std::cout << "\n\nYou suddenly find yourself in a forest clearing.\n";
std::cout << "and there he is, that annoying weathered statue.\n";
std::cout << "It gives you a long stare...\n";
std::cout << "\"Agh, I've had enough of you. Be gone!\"\n\n";
std::cout << "You stare blankly into the air...\n\n\n\n";
return 0;
}