#include <iostream>
void PrintIntroduction(int Difficulty)
{
std::cout << "\n\nLEVEL " << Difficulty;
std::cout << "\nYou work for Shadow, you need to break into Midas' Ghost headquarters..";
std::cout << "\nRetrieve the data from- THE DOOMSDAY DEVICE. Before it's too late!\n";
std::cout << "Using our energy detection scanners we've been able to create a very rough image on what this device looks like and to pinpoint it's weaknesses.\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 << "----------&&%&&&&&&&%&&&@@@@@@@&&&&---------------\n";
std::cout << "But this image is not clear enough, which is why we need you to get intel from these secretive files to develop a clearer visual. We're counting on you.\n\n";
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
//Declare 3 number code
const int CodeA = rand();
const int CodeB = rand();
const int CodeC = rand();
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//Print sum and product of 3 numbers
std::cout << std::endl;
std::cout << "+ The password into the secret files is made up of 3 numbers.\n";
std::cout << "+ These numbers add up to: " << CodeSum << std::endl;
std::cout << "+ They multiply to make: " << 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 player's guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\n***Well done agent, you've extracted a file! Keep going!***";
return true;
}
else
{
std::cout << "\n***Agent, you have entered the wrong code, be careful and try again!***";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxLevel = 5;
while (LevelDifficulty <= MaxLevel) //loop game until all levels completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); //Clears any errors
std::cin.ignore();//Discards the buffer
if (bLevelComplete)
{
++ LevelDifficulty;
}
}
std::cout << "\n***Well done agent, you've extracted enough files so now we can gain a better understanding of this device.***";
return 0;
}
Nice.
In the lesson you are asked to try ASCII art.
But there is one thing that isnt mentioned,
When you use \ it doesnt include it as part of a string.
Found that you actually have to use \\ in order for it to print out a single \
Hence why the ASCII art looks a little odd in my coding here
std::cout << "\n\n _____ ____ _____ ______ _ _ _____ _____ \n";
std::cout << " / ____/ __ \\| __ \\| ____| | | | | /\\ | __ \\| __ \\ \n";
std::cout << " | | | | | | | | | |__ | |__| | / \\ | |__) | | | |\n";
std::cout << " | | | | | | | | | __| | __ | / /\\ \\ | _ /| | | |\n";
std::cout << " | |___| |__| | |__| | |____ | | | |/ ____ \\| | \\ \\| |__| |\n";
std::cout << " \\_____\\____/|_____/|______| |_| |_/_/ \\_\\_| \\_\\_____/ \n\n";
But when you compile it it look how you expect it should.
LOL has to edit as even in this text box, you need to use \\\ in order for it to print out \\
Guess how many 's I needed to printout \\\
Interesting, I needed more \'s to do the \\ in the line above that the first time I wrote it… But back to 3 in this line…
1 Like