-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTripleX.cpp
71 lines (58 loc) · 2.09 KB
/
TripleX.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <ctime>
void PrintIntroduction(int Difficulty)
{
std::cout << "\n\nYou are a secret agent breaking into a level " << Difficulty;
std::cout << " secure server room...\nEnter the correct code to continue...\n\n";
}
bool PlayGame(int Difficulty)
{
// Print welcome message to the terminal
PrintIntroduction(Difficulty);
// Declare 3 number code
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;
// Print CodeSum and CodeProduct to the terminal
std::cout << std::endl;
std::cout << "+ There are 3 numbers in the code";
std::cout << "\n+ The codes add-up to: " << CodeSum;
std::cout << "\n+ The codes multiply to give: " << CodeProduct << 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 the player guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\n*** Well done agent! You have extracted a file! Keep going! ***";
return true;
}
else
{
std::cout << "\n*** You entered the wrong code! Careful agent! Try again! ***";
return false;
}
}
int main()
{
srand(time(NULL));// create new random sequence based on time of day
int LevelDifficulty = 1;
int const MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty)// Loop the game until all levels completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();// Clear any errors
std::cin.ignore();// Discards the buffer
if (bLevelComplete)
{
// increase the level difficulty
++LevelDifficulty;
}
}
std::cout << "\n*** Great work agent! You got all the files! Not get out of there ***\n";
return 0;
}