I completed the course last night and I completed level 3 . I didn’t know whether it was because it was already midnight or that I’m bad at math.
So, I tried it the next day, and I’m definitely bad at math.
Looking at the program again in the morning I wanted to try some other things with it, so I fiddled around.
Changes:
- Made the intro section play only once per game start and other formatting changes
- Allow players to select the difficulty at the start (basically the mod operator is now
Level + Selected Difficulty
)
Code:
#include <iostream>
#include <ctime>
void PrintIntroduction()
{
// print game intro
std::cout << R"(
________________________________________________________
(-) (-) (-)
.-'-'-. .-'-'-. .-'-'-.
|;:.._| |;:.._| |;:.._|
|-...-| |-...-| |-...-|
`-...-' `-...-' `-...-'
________________________________________________________
)" << '\n';
std::cout << "As an alchemist you're working with some dangerous stuff!...\n";
std::cout << "Mix the correct amount of ingredients and don't explode\n";
std::cout << "========================================================\n\n";
}
bool PlayGame(int Level, int DifficultySelect)
{
//declare 3 numbers
const int CodeA = rand() % Level + DifficultySelect;
const int CodeB = rand() % Level + DifficultySelect;
const int CodeC = rand() % Level + DifficultySelect;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProd = CodeA * CodeB * CodeC;
//print CodeSum and CodeProd
std::cout << std::endl;
std::cout << " +++ (Level "<< Level << ") +++\n";
std::cout << "=============================================\n";
std::cout << "+ You are mixing 3 ingredients in this potion\n";
std::cout << "+ The 3 ingredients should add up to: " << CodeSum << " ml\n";
std::cout << "+ The 3 ingredients should multiply to: " << CodeProd << " ml\n";
//display possible numbers
std::cout << "+ Possible Numbers: 1 to " << Level + DifficultySelect;
//Players inputs guesses
std::cout << std::endl;
std::cout << "Enter the quantities for the 3 ingredients:\n";
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProd = GuessA * GuessB * GuessC;
//Print out sums and products
std::cout << std::endl;
std::cout << "The sum of all ingredients are: " << GuessSum << " ml\n";
std::cout << "The product of all ingredients are: " << GuessProd << " ml\n";
//Checking the answer correct
std::cout << std::endl;
if (GuessSum == CodeSum && GuessProd == CodeProd)
{
std::cout << "++++ Congratulations! You don't explode! Level " << Level << " Completed! ++++\n\n";
return true;
}
else
{
std::cout << "---- The potion explodes in your face! Try again ----\n\n";
return false;
}
}
int main()
{
//Rand and Mod Testing
// int TestValues;
// while (TestValues <= 5)
// {
// std::cout << rand() % 2 << '\n';
// ++TestValues;
// }
// return 0;
srand(time(NULL));
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
PrintIntroduction();
//Select Difficulty
std::cout << "Select Difficulty:\n";
int DifficultySelect = 1;
std::cin >> DifficultySelect;
while (LevelDifficulty <= MaxDifficulty) //Until all levels are completed
{
bool bLevelComplete = PlayGame(LevelDifficulty,DifficultySelect);
std::cin.clear(); //clears any errors
std::cin.ignore(); //discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << R"(
==================================================
You have made all the potions! Rest easy Alchemist.
==================================================
)" << '\n';
return 0;
}
Screens: