Hello friends!
I couldn’t really figure out why we were using the variable “Difficulty” as opposed to just using the variable “LevelDifficulty” all along. If one of you knows the reason for this it would be much appreciated!
Here is the code for my game!
#include <iostream>
#include <ctime>
void PrintIntroduction(int LevelDifficulty)
{
std::cout << "\n\n 00000000 000000000\n";
std::cout << " 00 00 00 00\n";
std::cout << " 00 00 00 00\n";
std::cout << " 00 00 00 00\n";
std::cout << "00 00==========00 00\n";
std::cout << " 00 00 00 00\n";
std::cout << " 00 00 00 00\n";
std::cout << " 00 00 00 00\n";
std::cout << " 00000000 00000000\n";
;
std::cout << "\nYou are a scientist breaking into a level " << LevelDifficulty;
std::cout << " secret government lab...\nYou need to enter the correct number combination in order to steal one of the cures to all ailments...\n\n";
}
bool PlayGame(int LevelDifficulty)
{
PrintIntroduction(LevelDifficulty);
const int CodeA = rand() % LevelDifficulty + LevelDifficulty;
const int CodeB = rand() % LevelDifficulty + LevelDifficulty;
const int CodeC = rand() % LevelDifficulty + LevelDifficulty;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProd = CodeA * CodeB * CodeC;
std::cout << "+ There are 3 numbers in the code";
std::cout << "\n+ The code's sum adds up to: " << CodeSum;
std::cout << "\n+ The product is equal to: " << CodeProd << std::endl;
// Store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// Check if player's guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProd)
{
std::cout << "\nGood job! You got " << LevelDifficulty << " of them!";
return true;
}
else
{
std::cout << "\nWrong code...Try again...";
return false;
}
}
int main() //loop game until all levels completed
{
srand(time(NULL));
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
while(LevelDifficulty <= MaxDifficulty)
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // clears error from input
std::cin.ignore(); // skips to the next line after error
if (bLevelComplete)
{
// increase the level difficulty
++LevelDifficulty;
}
}
std::cout << "\nAll the cures are in your hands now! With great power comes great responsibility...";
return 0;
}