This is my code after i updated my stings to reflect the game in. In the Comparing Values Lecture.
To save your friends you are going to steal level 1 classified files from FBI.
To achieve that you are going to need to find 3 number with the help of given information.
There are 3 numbers in the code
The codes add-up to: 24842
The codes multiply to give: 500801802
So thats my output for the game. I used a simple story. Nothing extra ordinary.
So I took just a little break from “my” game to go and try and write the one Gavin was doing from memory over what we learned. Needed some hints here and there, but it was a great exercise I think.
Also! I had fun with the coding and did something that I thought was cool, and not exactly sure how I managed to swing it, but the code fell in the right place. Now my code not only counts down the levels remaining, but also keeps track of how many times you’ve failed, and if you fail 3 times, it “sets off an alarm” and kicks you out of the game. Did this through putting a few if children in the if parents (not sure if that lingo works but it’s fun to try!)
#include
void Intro(int Difficulty)
{
std::cout << “\n\nYou are a secret agent breaking into a level " << Difficulty;
std::cout << " secure server.\n\nEnter the correct code to continue to the next level.”;
}
bool PlayGame(int Difficulty, int Finished, int Failures)
{
Intro(Difficulty);
const int CodeA = 1;
const int CodeB = 2;
const int CodeC = 3;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
std::cout << "\n\n + 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::cout << "\n\nEnter Code:\n\n";
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
if(Difficulty!=Finished)
{
std::cout << "\nYou cracked the code for the Level " << Difficulty;
std::cout << " server! Only " << Finished-Difficulty;
std::cout << " to go!\n";
return true;
}
else
{
return true;
}
}
else
{
if(Failures>0)
{
std::cout << "\nCareful Agent, only " << Failures;
std::cout << " tries left!";
return false;
}
else
{
std::cout << "\nBeeeeeeooooooooooowwww!!! Intruder Alert! Intruder Alert!!\n";
return false;
}
}
}
int main()
{
int Level = 1;
int Failures = 2;
const int MaxLevel = 5;
while (Level <= MaxLevel) // Loop the game until all levels are completed
{
bool LevelComplete = PlayGame(Level, MaxLevel, Failures);
std::cin.clear();
std::cin.ignore();
if (LevelComplete)
{
++Level;
}
else
{
if(Failures>0)
{
--Failures;
}
else
{
return 0;
}
}
}
std::cout << "\nYou're in! You've got all the addresses of all the bad guys in the world...no more hiding for them. Congratulations Agent, the world is safe yet again!\n";
return 0;
}
Well I’m only on Lecture 24, so I’ve yet to actually get into the mechanics and logic of the game, but it’s simple print statemtns atm…
Awesome work guys! Keep it up!
Before watching last video of Triple X game I tried to figure it out myself and this is what I came up with:
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
int RandomDifficulty = Difficulty + 4;
const int CodeA = rand() % RandomDifficulty + 1;
const int CodeB = rand() % RandomDifficulty + 1;
const int CodeC = rand() % RandomDifficulty + 1;
const int CodeSum = CodeA+CodeB+CodeC;
const int CodeMulti = CodeA*CodeB*CodeC;
Ok I finished mine properly now, with ascii art included…
#include <iostream>
#include <ctime>
void PrintIntro(int Difficulty)
{
//print welcome message to terminal as a string
std::cout << R"( _____ _ _ __ __
|_ _| (_) | | \ \ / /
| | _ __ _ _ __ | | ___ \ V /
| || '__|| || '_ \ | | / _ \ / \
| || | | || |_) || || __// /^\ \
\_/|_| |_|| .__/ |_| \___|\/ \/
| |
|_| )" << '\n';
std::cout << "\nYou are the Chinese superhero NatBam. Your arch nemesis the Diddler has left 5 diddles all over Gotnam in an attempt to prove his mental prowess is greater than yours!";
std::cout << "\n\nEnter the correct codes for diddle Level " << Difficulty << " to deactivate it!\n";
}
bool PlayGame(int Difficulty, int MaxLevel)
{
PrintIntro(Difficulty);
//declare 3 number code
const int CodeA = rand() % Difficulty + 3;
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 variables to the terminal
std::cout << std::endl;
std::cout << "- There are 3 numbers in the code";
std::cout << "\n- The code adds up to: " << CodeSum;
std::cout << "\n- The code multiplies to give: " << CodeProduct << '\n' << '\n';
//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 guess is correct and change final statement if player beats game.
if (Difficulty == MaxLevel)
{
std::cout << "\nAll diddles solved!\n";
return true;
}
else if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\n*** Well done, you solved the Level " << Difficulty << " diddle! ***\n";
return true;
}
else
{
std::cout << "\n*** You entered the wrong code, don't let the Diddler outsmart you. Try again! ***\n";
return false;
}
}
int main()
{
srand(time(NULL)); // create new random sequence based on time of day
int LevelDifficulty = 1;
const int MaxLevel = 5;
while (LevelDifficulty <= MaxLevel) // Loop game until all levels complete
{
bool bLevelComplete = PlayGame(LevelDifficulty, MaxLevel);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer (clears 1 character from the stream buffer)
// Final print statement when max level.
if (LevelDifficulty == MaxLevel)
{
std::cout << "\nYou outsmarted the Diddler and saved GotNam! Congratulations!\n";
break;
}
else if (bLevelComplete)
{
++LevelDifficulty; // Increase Level Difficulty
}
}
return 0;
}
Used some nifty if/else if statements to keep the code short for changing print lines on the last level.
Did notice that going through levels with the ‘difficulty’ variable as the mod range could limit the first couple of rounds to being very easy, and then medium difficulty on the last couple. So, I changed one of the codes to have a range of 3+. This makes the beginning levels challenging, and the last few levels very thought provoking!
Cool little game really…
void PrintIntroduction(int Difficulty)
{
//ASCII Art
std::cout << "\n\n" << R"( .
/|
____...,---.___..__,) |
,_.-._ ,._,.--'''''' ' ;
/ '-' ) /
,'_._. `_ ,' :
`-. -. _ ' ;
)`-. `. /; ) ) ,' /
'. `. -. ( \ | =' .' ;
`. '-._+ .\= \.-'-'-.| ; / :'
`. \\ `- `.+' ;
.-. `. ,-+,' = _ (_ ; .'
; (_ /: =,( O\ O ).J
`. =`. ;' =\ \ 7P '
`-. '-: .' = \ \ (: :) )
`--| ; = `.`. `=="./
; : `-`.__.' )
: | ;
'.'.= -. . +
,'`) := \ , / `.
) =| `. ,+-.-'-+. ;.
; \: /| | ; `._ =)
: ( `-' | (/ kOs ; ;
( |; (: ) | :
`- / )| ; ) |)
(_/ `-' `-' )" << std::endl << std :: endl;
//Set up the storyline
std::cout << "You enter what you think must be the villain's lair, ready to fight. \n";
std::cout << "Unfortunately, you need to get past a level " << Difficulty;
std::cout << " security door to continue. \nEnter the correct code to continue. \n \n";
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
//Declare the code
const int CodeA = 4;
const int CodeB = 7;
const int CodeC = 3;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//Print sum and product to terminal
std::cout << "There are 3 numbers in the code. \n";
std::cout << "The codes add up to: " << CodeSum;
std::cout << "\nThe codes multiply to give: " << CodeProduct << std::endl;
// Get player guesses
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// Compare user input to determine win/loss.
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nYou make it past the security door and enter the next room! \n";
return true;
}
else
{
std::cout << "\nYou fail to open the door. You take a deep breath and try again. \n";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels are completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // clear errors
std::cin.ignore(); // discard buffers
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "You enter the final room, and knock the villain out with one punch. \n";
std::cout << "You take him to the super secure prison, and the day is saved! Good job! \n";
return 0;
}
Here’s my code so far!
#include <iostream>
void PrintWelcomeMessage () // Printing of a welcome message to the terminal
{
std::cout<<"\n88 88 88 ";
std::cout<<"\n88 88 88 ";
std::cout<<"\n88 88 88 ";
std::cout<<"\n88,dPPYba, ,adPPYYba, 88,dPPYba, 8b d8 88 ,adPPYba, 8b,dPPYba, ";
std::cout<<"\n88P' \"8a \"\" `Y8 88P' \"8a `8b d8' 88 a8\" \"8a 88P' `\"8a ";
std::cout<<"\n88 d8 ,adPPPPP88 88 d8 `8b d8' 88 8b d8 88 88 ";
std::cout<<"\n88b, ,a8\" 88, ,88 88b, ,a8\" `8b,d8' 88 \"8a, ,a8\" 88 88 ";
std::cout<<"\n8Y\"Ybbd8\"' `\"8bbdP\"Y8 8Y\"Ybbd8\"' Y88' 88 `\"YbbdP\"' 88 88 ";
std::cout<<"\n d8' ";
std::cout<<"\n d8' ";
std::cout << "\n\nYou are an archeologist that've just uncovered a secret tomb in ancient Babylon.\n";
std::cout << "\nA set of consequent locked doors with traps are between you and the treasure.";
}
void PrintIntroduction(int Difficulty)
{
// Printing of a current player's position in the course of game
std::cout << "\nYou are in front of the door number " << Difficulty <<".";
std::cout << "\nTo open it you should pass an exam of ancient mathemathitians:\n";
}
bool PlayGame(int CurrentDifficulty)
{
PrintIntroduction(CurrentDifficulty);
// Declaration of 3 number code
const int CodeA = 1;
const int CodeB = 2;
const int CodeC = 3;
/* Just some multiline
comment
*/
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//Printing the result
std::cout << "\nThe are three numbers in a code\n";
std::cout << "And they add-up to: " << CodeSum;
std::cout << "\nWhile thir product is: " << CodeProduct;
std::cout << "\n\nPlease, enter your guess of three numbers, each separated by at least one space: ";
// Storing player's guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC ;
int GuessProduct = GuessA * GuessB * GuessC ;
// Checking if the player's guess is correct
if (GuessSum==CodeSum && GuessProduct==CodeProduct)
{
std::cout<<"\nIt was the right code! Now on to the next door.\n";
return true;
}
else
{
std::cout<<"\n\nOh no!...The code is wrong and a trap teleports you to the very first door. \nThe puzzle is reset and all the progress is lost...\n";
return false;
}
}
int main()
{
int LevelDifficulty=1;
const int MaxDifficulty=5;
PrintWelcomeMessage ();
while (LevelDifficulty<=MaxDifficulty) // Loop the game untill all levels are completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
{
++LevelDifficulty;
}
else
{
LevelDifficulty=1;
}
}
std::cout<<"\n\n Hurray! You've passed all the doors and the treasure is yours!\n";
return 0;
}
MY TRIPLLE-X PROGRESS SO FAR
#include <iostream>
void PrintIntroduction(int Difficulty)
{
//print the welcome and intro message to tripleX game
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\n";
std::cout << " \n";
std::cout << " __________________________________________________________________________________________________ \n";
std::cout << " (010010101 ________________________________0100 ) \n";
std::cout << " | 010010010 0 0 010010 | \n";
std::cout << " | 01001011 0 0 010010 | \n";
std::cout << " | 01001010 0 0 010010 | \n";
std::cout << " | 01001010 0 0 01001110 | \n";
std::cout << " | 0100101001010 0 0 0100101010101010011 | \n";
std::cout << " |__________________________0 0______________________________| \n";
std::cout << "____________________________________________________________________________________________________________________________________ \n";
std::cout << "HACKERMAN::HACKERMAN::HACKERMAN::HACKERMAN::HACKERMAN::HACKERMAN::HACKERMAN::HACKERMAN::HACKERMAN::HACKERMAN::HACKERMAN::HACKERMAN:: \n\n";
std::cout << "\n\nyou are a professional hacker breaking into server " << Difficulty;
std::cout << " ||there are 10 servers in an room enter the correct pin to destroy the complete server room \n";
std::cout << "if you sucessfully destroy server room you win \n";
std::cout << "you receice reward of $1000 on every level......\n\n";
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
//declaring 3 number code need to destroy server
const int CodeA = rand();
const int CodeB = rand();
const int CodeC = rand();
//sum and product
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//it is at the initialising stage sum and product to terminal for printing
std::cout << "*there are 3 numbers in the code ";
std::cout << "\n*the code will be add up to: " << CodeSum;
std::cout << "\n*the product of the code is: " << CodeProduct;
//store playerguess
std::cout << std::endl;
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
//check player guess
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\ncongrats $1000 cr. in your bank balance ";
return true;
}
else
{
std::cout << "\nTRY AGAIN***ERROR**CODE*** stupid you have entered wrong code ";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
int const MaxDifficulty = 10;
while (LevelDifficulty <= MaxDifficulty) // Loop the game until all level are completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // Clears an errors
std::cin.ignore(); // Discard the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "\n\nGreat work HACKERMAN. cograts you have sucseefully corupted and destroyed all 10 servers \nstd::cout |||Sir,you have $10,000 in your bank ******press**to**continue*****";
return 0;
}
void PrintIntroduction(int Difficulty){
std::cout << "\nYou are on the level " << Difficulty << " of the dungeon. There is a locked door in front of you.\n";
std::cout << "The door opens with 3-number code.\n";
}
bool PlayGame(int Difficulty){
PrintIntroduction(Difficulty);
//Declare 3 number code
const int CodeA = 2;
const int CodeB = 3;
const int CodeC = 4;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// Print sum and product to the terminal
std::cout << "Someone left you some hints.\n";
std::cout << "The codes add-up to: \t\t" << CodeSum << '\n';
std::cout << "The codes multiply to give: \t" << CodeProduct << '\n';
//Player guess declaration
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
std::cout << "You entered: \t" << GuessA << ' ' << GuessB << ' ' << GuessC << '\n';
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
//Checking answer
if(GuessSum == CodeSum && GuessProduct == CodeProduct){
std::cout << "The door opens loudly, and you continue your descent.\n\n";
return true;
}
else{
std::cout << "BOOOOOOOOM. The lock explodes. You are trapped int the dungeon.\n\n";
return false;
}
}
int main() {
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
bool bLevelComplete = true;
while(LevelDifficulty <= MaxDifficulty){
bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
LevelDifficulty++;
}
std::cout << "\nCongratulations! You found a dragon!\n";
return 0;
}
#include
void GameStart()
{
//welcome message for game
std::cout << std::endl;
std::cout << "### ### ## ##";
std::cout << " \n### ### ## ##";
std::cout << " \n######### ##";
std::cout << " \n######### ## ##";
std::cout << " \n### ### ##";
std::cout << " \n### ### ## ##" << std::endl;
std::cout <<"\nYou are a robber on a robbery scene and want to break the vault to steal a DIAMOND \n";
std::cout << "Your only way to open the vault is by feeding a correct code \n\n";
}
void GameIntro(int Difficulty)
{
//Level message for game
std::cout << "LEVEL " << Difficulty;
}
bool PlayRobberyGame(int Difficulty)
{
GameIntro(Difficulty);
// declarations
const int CodeX = 3;
const int CodeY = 5;
const int CodeZ = 1;
const int CodeSum = CodeX + CodeY + CodeZ;
const int CodeProduct= CodeX * CodeY * CodeZ;
// game start messages
std::cout << std::endl << std::endl;
std::cout << "Enter 3 digit code to get access";
std::cout << "\nwhose sum of number is " << CodeSum;
std::cout << "\nwhile product is " << CodeProduct << std::endl << std::endl;
std::cout << "Enter the code now and press 'Enter' ";
std::cout << std::endl;
//guessing the code
int GuessX, GuessY, GuessZ;
std::cin >> GuessX;
std::cin >> GuessY;
std::cin >> GuessZ;
std::cout << "You entered " << GuessX << GuessY << GuessZ;
int GuessSum = GuessX + GuessY + GuessZ;
int GuessProduct = GuessX * GuessY * GuessZ;
std::cout << std::endl;
if (GuessSum == CodeSum && GuessProduct == CodeProduct) {
std::cout << "You WIN \n\n";
return true;
}
else
{
std::cout << "BANG! There was a small explosion beneath your feet inside the floor.\n";
std::cout << "You never noticed the trap around you if you enter the wrong code you are dead.\n";
std::cout << "Alas! You feel the burn on your legs while you fall away and then faint out. \n\n *TRY AGAIN*\n\n";
return false;
}
}
int main()
{
const int MaxDifficulty = 4;
int LevelDifficulty = 1;
GameStart();
while (LevelDifficulty <= MaxDifficulty)
{
bool bLevelComplete = PlayRobberyGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
{
LevelDifficulty += 1;
}
}
std::cout << "Suddenly theres a click sound and VAULT DOOR opens Byitself....You Did It\n\n";
std::cout << "****CONGRATULATIONS*****\n\n";
std::cout << "You are a MILLIONARE\n\n";
return 0;
}