I’m going to be honest, I didn’t even play it because I’m so bad at math! Overall though, this was a brilliant intro to C++ and I feel like I’ve genuinely achieved something.
#include <iostream> //import input output stream
#include <ctime> //import our computer's time
void PrintIntroduction(int Difficulty)
{
std::cout << "\nYou broke into the Evil Wizard's Lair. Congratulations. Unfortunetly, it was a trap.\n";
std::cout << "On the table in front of you, vials lay scattered with numbers written on them.\n";
std::cout << "You find a note 'The room is filling with poison gas. ";
std::cout << "You must mix three ingredients together ten times, mix, and then drink the final potion to stop the poison from killing you.\n";
//must be a better way of doing this
if (Difficulty == 1)
{
std::cout << "\nMix the " << Difficulty << "st Potion";
}
if(Difficulty == 2)
{
std::cout << "\nMix the " << Difficulty << "nd Potion";
}
if (Difficulty == 3)
{
std::cout << "\nMix the " << Difficulty << "rd Potion";
}
if (Difficulty != 1 && Difficulty != 2 && Difficulty !=3)
{
std::cout << "\nMix the " << Difficulty << "th Potion";
}
}
void PrepareToDie()
{
std::cout << "\n@@@@@@@ @@@@@@@ @@@@@@@@ @@@@@@@ @@@@@@ @@@@@@@ @@@@@@@@ @@@@@@@ @@@@@@ @@@@@@@ @@@ @@@@@@@@ \n";
std::cout << "@@@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@ @@@@@@@@ @@@@@@@@ @@@ @@@@@@@@ \n";
std::cout << "@@! @@@ @@! @@@ @@! @@! @@@ @@! @@@ @@! @@@ @@! @@! @@! @@@ @@! @@@ @@! @@! \n";
std::cout << "!@! @!@ !@! @!@ !@! !@! @!@ !@! @!@ !@! @!@ !@! !@! !@! @!@ !@! @!@ !@! !@! \n";
std::cout << "@!@@!@! @!@!!@! @!!!:! @!@@!@! @!@!@!@! @!@!!@! @!!!:! @!! @!@ !@! @!@ !@! !!@ @!!!:! \n";
std::cout << "!!@!!! !!@!@! !!!!!: !!@!!! !!!@!!!! !!@!@! !!!!!: !!! !@! !!! !@! !!! !!! !!!!!: \n";
std::cout << "!!: !!: :!! !!: !!: !!: !!! !!: :!! !!: !!: !!: !!! !!: !!! !!: !!: \n";
std::cout << ":!: :!: !:! :!: :!: :!: !:! :!: !:! :!: :!: :!: !:! :!: !:! :!: :!: \n";
std::cout << " :: :: ::: :: :::: :: :: ::: :: ::: :: :::: :: ::::: :: :::: :: :: :: :::: \n";
std::cout << " : : : : : :: :: : : : : : : : : :: :: : : : : :: : : : : :: :: \n";
std::cout << "";
}
void YouWin()
{
std::cout << "\nYou mix all the potions together.... down the hatch!\n";
std::cout << "Congratulations, you live... for now..\n";
}
void YouDie()
{
std::cout << "You ran out of potions to drink... you suffer a slow, painful death.\n";
}
//void function doesn't return any data type
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
//define vriables - declare 3 number code
const int CodeA = rand() % Difficulty + Difficulty;
const int CodeB = rand() % Difficulty + Difficulty;
const int CodeC = rand() % Difficulty + Difficulty;
//calculate
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//output calculations above
std::cout << "\n+ 3 vials must be mixed together.";
std::cout << "\n+ The 3 numbers on the vials add up to: " << CodeSum;
std::cout << "\n+ The 3 numbers on the vials multiply together to: " << CodeProduct;
std::cout << "\n\n- Mix the vials: \n";
//prepare vars to store user input
int GuessA, GuessB, GuessC;
//receive user input
std::cin >> GuessA >> GuessB >> GuessC;
//calculate
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
//check if player guess is correcty
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
//std::cout << "\nYou Survived! ...For now.\n";
std::cout << "Your potion mix fizzes and pops - it looks like you mixed this one right.\n";
return true;
}
else
{
//std::cout << "\nYou Died a horrible, painful death!!\n";
std::cout << "\nThis vial fizzes and splutters... that doesn't look right..\n";
return false;
}
}
//main is required to compile
int main()
{
srand(time(null)); //creates new random sequence based on time of day.
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
int MaxTries = 5;
std::cout << PrepareToDie;
while (LevelDifficulty <= MaxDifficulty && MaxTries > 0) //loop game until max difficilty complete
{
if (MaxTries !=0) //loops the game until all levels are complete or max tries runs out.
{
bool bLevelComplete = PlayGame(LevelDifficulty); //checks if level is complete
std::cin.clear(); //clears any errors
std::cin.ignore(); //discards the buffer
if (bLevelComplete)
{
//increase the level difficulty
++LevelDifficulty;
MaxTries = 5;
}
else
{
--MaxTries;
std::cout << "\nCareful, you're running out of liquids.\n";
std::cout << "\nIt looks like you can mix " << MaxTries << " more potions with these vials.\n";
}
}
}
if (MaxTries == 0)
{
YouDie();
}
else
{
YouWin();
}
return 0;
}```