# So I finished my first (very simple) game

So I finished my very simple text game as part of the Unreal 4 c++ course. It has taken me about 4 days following along with the lectures but I am proud of what I have accomplished thus far. Feel free to take a look at the game yourself and even have a crack if you fancy.

p.s. in the course we set const int CodeA/B/C = rand() % Difficulty + Difficulty;. This was however a little difficult so I stuck with the initial ‘Difficulty + 1’ to keep it simple.

Thanks Guys.

#include

#include

void PrintIntroduction (int Difficulty)

``````{

std:: cout << "\n\nYou are attempting to gain access to level " <<Difficulty;

std:: cout << " of the Wizard's Tower in order to steal the dark secrets from further within.\nIn order to gain access you must correctly enter a mysterious runic code for the door...\n\n";

}
``````

bool PlayGame (int Difficulty)

{

``````PrintIntroduction (Difficulty);

//Declare 3 number code

const int CodeA = rand() % Difficulty + 1;

const int CodeB = rand() % Difficulty + 1;

const int CodeC = rand() % Difficulty + 1;

const int CodeSum = CodeA + CodeB + CodeC;

const int CodeProduct = CodeA * CodeB * CodeC;

//Print CodeSum and CodeProduct to the terminal

std::cout << "+ There are 3 numbers YOU must enter for the code";

std::cout << "\n+ The correct numbers in the code add up to: " << CodeSum;

std::cout << "\n+ The correct code numbers also multiply to give: " << CodeProduct << std:: endl;

// Store Player Guess

int GuessA, GuessB, GuessC;

std::cin >>GuessA >> GuessB >> GuessC;

std::cout << "\nYou entered: " << GuessA << GuessB << GuessC;

int GuessSum = GuessA + GuessB + GuessC;

int GuessProduct = GuessA * GuessB * GuessC;

//Check if the players guess is correct

if (GuessSum == CodeSum && GuessProduct == CodeProduct)

{

std::cout << "\n\n*** The door begins to creak and warp open. You have entered the code correctly, progress on to the next level. ***";

return true;

}

else

{

std::cout << "\n\n*** The door remains lifeless - try again! ***";

return false;

}
``````

}

int main()

{

``````srand(time(NULL));

int LevelDifficulty = 1;

const int MaxDifficulty = 5;

while (LevelDifficulty <= MaxDifficulty) //While loop will loop game until all levels are completed

{

bool bLevel1Complete = PlayGame(LevelDifficulty);

std::cin.clear(); // Clears amy errors

if (bLevel1Complete)

{

++LevelDifficulty;  //increase level difficulty

}

}

std::cout << "\n\n ***You have reached the summit of the tower and the treasures within are now yours! Congratulations! ***\n";

return 0;
``````

}