#include <iostream>
#include <string>
std::string GetOrdinal(int Value)
{
switch (Value)
{
case 1:
return "tenth";
case 2:
return "nineth";
case 3:
return "eighth";
case 4:
return "seventh";
case 5:
return "sixth";
case 6:
return "fifth";
case 7:
return "fourth";
case 8:
return "third";
case 9:
return "second";
case 10:
return "first";
default:
return "unknown";
}
// credit to community.
}
void PrintIntroduction(int Difficulty)
{
// Print welcome messages to the terminal
std::cout << "\n\n ______||____ \n";
std::cout << " /////////// |\n";
std::cout << "/////////// |\n";
std::cout << "| _ | |\n";
std::cout << "|[] | | []|[]|\n";
std::cout << "|___|_|___|__|\n";
std::cout << "___/_/________\n\n";
// credit to comunity.
std::cout << "\n\nYou were exploring a haunted house, when someone knocked you out cold....... you are on the " << GetOrdinal(Difficulty);
std::cout << " floor \nEnter the correct codes to get out in time...alive.... \n";
}
bool bPlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
// Declare 3 number code
const int CodeA = 4;
const int CodeB = 3;
const int CodeC = 2;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// Print CodeSum and CodeProduct to the terminal
std::cout << "\n\nThe spirit helping you gives you the following clues that.. 'it' ..has figured out over the years: " << "\n\n+ There are three 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 is correct or wrong
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\n ****************************************************************************************************** \n The good part is that you got the code correct, and no one noticed you! \n" << "The sad part is that you found another door in front of you... continue and you may just find freedom! \n ****************************************************************************************************** \n\n\n";
return true;
}
else
{
std::cout << "\n******* You got it wrong, the sprits catch you trying to escape, be carefull! Try Again. ******* \n\n";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
int const MaxDifficulty = 10;
while (LevelDifficulty <= MaxDifficulty) // loop game untill all levels are completed
{
bool bLevelComplete = bPlayGame(LevelDifficulty);
if (bLevelComplete)
{
++LevelDifficulty;
}
std::cin.clear(); //clears any errors
std::cin.ignore(); //Discards the buffer
}
std::cout << "\n *** Great work! Says the spirit..... As you try to walk out... 'thud!' YOu CanNOt EsScApe! Muhahwhahahahaaha! And you realise that you were just another spirit, and were never a human! ***\n\n\n\n";
return 0;
}
Hereâs a copy of my work so far!
#include
int main()
{
//Print Welcome message to the Terminal
std::cout << "You are a super hero with special hacking abilities";
std::cout << std::endl;
std::cout << "You need to save the world, but in order to diffuse the bomb, you need to acces the correct code..." << std::endl;
//Declare 3 number code
const int CodeA = 4;
const int CodeB = 7;
const int CodeC = 2;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//Print Product and Sum to the Terminal
std::cout<<std::endl;
std::cout<< "+ there are three numbers in the code." << std::endl;
std::cout<< "+ the numbers add up to: " << CodeSum << std::endl;
std::cout<< "+ the numbers multiply to give: "<< CodeProduct << std::endl;
int GuessA, GuessB, GuessC;
std::cin >> GuessA;
std::cin >> GuessB;
std::cin >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "You did it! The bomb is diffused and now you can go party with the rest of the city!";
}
else
{
std::cout << "Oh no! The code was incorrect. The bomb immediatly self destructed and now you and the city are dead!";
}
return 0;
}
And now I have some ASCII art of my own!
#include
void PrintIntroduction ()
{
//Print Welcome message to the Terminal
std::cout << "----------------------|0100011010|--------------------------\n"
"----------------------|0110100010|--------------------------\n"
"----------------------|1000111010|--------------------------\n"
" |__________| \n"
" [::::::::::] \n";
std::cout << "You are a super hero with special hacking abilities\n";
std::cout << "You need to save the world, but in order to diffuse the bomb, you need to acces the correct code...\n\n";
}
void PlayGame ()
{
PrintIntroduction();
//Declare 3 number code
const int CodeA = 4;
const int CodeB = 7;
const int CodeC = 2;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//Print Product and Sum to the Terminal
std::cout<< "+ there are three numbers in the code.\n";
std::cout<< "+ the numbers add up to: " << CodeSum << "\n";
std::cout<< "+ the numbers multiply to give: "<< CodeProduct << "\n";
//Stor 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
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nYou did it! The bomb is diffused and now you can go party with the rest of the city!";
}
else
{
std::cout << "\nOh no! The code was incorrect. The bomb immediatly self destructed and now you and the city are dead!";
}
}
int main()
{
PlayGame();
return 0;
}
Now, almost complete,
#include
void PrintIntroduction (int Difficulty)
{
//Print Welcome message to the Terminal
std::cout << "\n----------------------|0100011010|--------------------------\n"
"----------------------|0110100010|--------------------------\n"
"----------------------|1000111010|--------------------------\n"
" |__________| \n"
" [::::::::::] \n";
std::cout << "You are a super hero with special hacking abilities\n";
std::cout << "You need to save the world, but in order to diffuse the level " <<Difficulty << " bomb, you need to acces the correct code...\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 Product and Sum to the Terminal
std::cout<< "+ there are three numbers in the code.\n";
std::cout<< "+ the numbers add up to: " << CodeSum << "\n";
std::cout<< "+ the numbers multiply to give: "<< CodeProduct << "\n";
//Stor 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
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nYou did it! The bomb is diffused, now you need to diffuse the next one!\n";
return true;
}
else
{
std::cout << "\nOh no! The code was incorrect. The bomb's time is running out, hurry and try again!";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxLevel = 10;
while (LevelDifficulty <= MaxLevel)
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); //clears any errors
std::cin.ignore();//dis the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "Congrats! Your sweat is not in vain, all the bombs are diffused and the villain has long since fled. You can now go enjoy the party for saving the city!\n";
return 0;
}
This is my code so far till Chapter 28
#include <iostream>
void PrintIntroduction(int Difficulty)
{
// Print welcome messages to the terminal
std::cout << "\n\nYou are a secret agent breaking into a level " << Difficulty;
std::cout << " secure server room...\nYou need to enter the correct codes to continue...\n";
}
bool bPlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
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 CodeSum and CodeProduct to the terminal
std::cout << "\n+ There are 3 numbers in the code";
std::cout << "\n+ When you add the codes you will get: " << CodeSum;
std::cout << "\n+ When you multiply the codes you will get: " << 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 << "\nGood. Advancing to next level.";
return true;
}
else
{
std::cout << "\nOOPS!! Wrong Code. Please Retry.";
return false;
}
}
int main()
{
std::cout << "\n\n.------..------..------..------..------..------..------.\n";
std::cout << "|T.--. ||R.--. ||I.--. ||P.--. ||L.--. ||E.--. ||X.--. |\n";
std::cout << "| :/\\: || (\\/) || :/\\: || :/\\: || :/\\: || (\\/) || (\\/) |\n";
std::cout << "| :\\/: || :\\/: || (__) || :\\/: || :\\/: || :\\/: || :\\/: |\n";
std::cout << "| '--'T|| '--'R|| '--'I|| '--'P|| '--'L|| '--'E|| '--'X|\n";
std::cout << "`------'`------'`------'`------'`------'`------'`------'\n";
int LevelDifficulty = 1;
const int MaxLevel = 5;
while (LevelDifficulty <= MaxLevel)
{
bool bLevelComplete = bPlayGame(LevelDifficulty);
std::cin.clear(); // Clearns the error
std::cin.ignore(); // Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "\n\nCongratulations. You passed the all security levels. You Win";
return 0;
}
#include <iostream>
void PrintIntroduction(int Difficulty){
//printing starting messages here
std::cout<<std::endl;
std::cout << "\n\nYou are the inceptor and you need to break into someones mind vault.\n";
std::cout << "You have entered dream layer " << Difficulty << "\nand ";
std::cout << "you must figure out what numerical value is significant to the subject...\n";
std::cout << std::endl;
}
// tells the Player what level they have accomplished
void LevelUpdateMessage(int Difficulty) {
if (Difficulty == 1) {
std::cout << "You have broke into the first mind vault. Congragulations, but this is only the begginning...\n";
} else if (Difficulty == 2) {
std::cout << "You have broke into the second mind vault. You will need to be vigilant...\n";
}else if (Difficulty == 3) {
std::cout << "You have broke into the thrrd mind vault. Don't be afraid to use a little imagination...\n";
}else if (Difficulty == 4) {
std::cout << "You have broke into the 4th mind vault. Don't lose yourself here...\n";
}else if (Difficulty == 5) {
std::cout << "You have entered into LIMBO the fith mind vault. Everthing looks sooo real...\n";
}else if (Difficulty == 6) {
std::cout << "You are waiting for a train...you dont know where this train will take you, but...\n";
}else if (Difficulty == 7) {
std::cout << "Cobbs I dont think we are in Kansas anymore...\n";
}
}
//Tells Player how man chances are left
void ChancesLeftMessage(int Chances) {
if(Chances == 3) {
//Game losing message
std::cout<< "You will die as an old man filled with regret, waiting alone. You are lost in limbo...forever\n";
}else if (Chances == 2) {
std::cout << "Last Chance...Dont mess up!\n";
}else {
std::cout << "You have used " << Chances << " out of 3 chances!\n";
}
}
bool PlayGame(int Difficulty) {
PrintIntroduction(Difficulty);
//declared 3 number codes the player will have to guess
const int CodeA = rand();
const int CodeB = rand();
const int CodeC = rand();
const int MemorySum = CodeA + CodeB+ CodeC;
const int MemoryProduct = CodeA * CodeB * CodeC;
std::cout << "There are 3 numbers you must use to unlock the first memory.\n";
std::cout << "The memory recalls a sum total of " << MemorySum << " and,\n";
std::cout << "the synapses recollect a multiplied value of " << MemoryProduct << "!\n";
std::cout << "\n";
std::cout << "What are the three numbers that are significant to the subject's life?\n";
//Variables not initialized until the player guesses for each value in the console
//To store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
std::cout << std::endl;
// std::cout << "You said..." << GuessA << " and " << GuessB << " and " << GuessC << " Are you sure?";
//Used to compare the player's guesses.
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
//Comparing the Player's guess to the answers
if (GuessSum == MemorySum && GuessProduct == MemoryProduct) {
std::cout<< "Correct!\n";
return true;
} else {
std::cout<< "Failed!\n";
return false;
}
}
int main() {
const int MaxLevel = 7;
int LevelDifficulty = 0;
int Attempts = 0;
// Loop the game until player completes the MaxLevel.
while(LevelDifficulty <= MaxLevel) {
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();//clears any errors
std::cin.ignore();//discards the buffer
if (bLevelComplete) {
++LevelDifficulty;
LevelUpdateMessage(LevelDifficulty);
//increase level difficulty
} else {
++Attempts;
ChancesLeftMessage(Attempts);
if (Attempts == 3) {
return -1;
}
continue;
}
}
//Game winning message
std::cout << "Congrats Mr. Cobb, you will get to see your family again, live life to the fullest my friend! << "\(^-^)/" << \n";
return 0; //returning a zero signals the system a successful compile
}
My work so far, but I am thinking of making some changes
#include <iostream>
void PrintIntroduction(int Difficulty)
{
std::cout << " - You have 1 new message! - \n\n";
// Print welcome messages to the terminal
std::cout << "\"Greetings Agent X,\n";
std::cout << "We have a suspicion that one of the laboratories in north is developing a new deathly diseases to use it as a bio weapon.\n";
std::cout << "Your job is to break into the laboratory and get the necessary evidence so that we can expose their intestions.\"\n\n";
std::cout << "...time skip...\n\n";
std::cout << "\nYou have reached level " << Difficulty;
std::cout << " secure server room. \nHack the door lock. Enter the correct code and move on...\n\n";
}
bool bPlayGame(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 CodeSum and CodeProduct to the terminal
std::cout << " _____________________ \n";
std::cout << " | _________________ | \n";
std::cout << " | | | | \n";
std::cout << " | | _ _ _ | | \n";
std::cout << " | | | | \n";
std::cout << " | | L O C K E D | | \n";
std::cout << " | |_________________| | \n";
std::cout << " |_____________________| \n\n";
std::cout << "\nThere are three numbers in the code";
std::cout << "\n\nThe codes add-up to: " << CodeSum;
std::cout << "\nThe codes multiply to: " << 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 players guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nYou got in and collected some evidence. Continue to get more. ";
return true;
}
else
{
std::cout << "\nWrong input. Careful Agent. Try again.";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
int const MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty) // Loop game until all level completed
{
bool bLevelComplete = bPlayGame(LevelDifficulty);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "\n\"Well done. You have collected all the evidence. Good job, Agent X.\"";
return 0;
}
#include <iostream>
void PrintIntroduction(int Difficulty)
{
std::cout << std::endl;
std::cout << std::endl;
std::cout << " SSS PPPP L III N N TTTTTT EEEE RRRR CCC EEEE L L\n";
std::cout << "S P P L I NN N TT E R R C E L L\n";
std::cout << " SSS PPPP L I N N N TT EEE RRRR C EEE L L\n";
std::cout << " S P L I N NN TT E R R C E L L\n";
std::cout << "SSSS P LLLL III N N TT EEEE R RR CCC EEEE LLLL LLLL\n";
// WillkommensgruĂ des Programms
std::cout << std::endl;
std::cout << "Du bist Sam Fisher, und brichst in einen geheimen Serverraum ein. \n Level " << Difficulty << " \n";
std::cout << "Du brauchst den korrekten Zugangscode, um weiterzukommen\n";
}
bool PlayGame(int Difficulty)
/* Ăbergabeparameter Difficulty deklariert, erhält Wert beim Aufruf aus main Funktion
LevelDifficulty kann nicht verwendet werden, da nur innerhalb main Funktion gĂźltig
*/
{
PrintIntroduction(Difficulty); // Ăbergabe Difficulty an PrintIntroduction()
// Declare 3 Number Code
const int CodeA = rand();
const int CodeB = rand();
const int CodeC = rand();
// Declare Product and Sum of the Codes
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProd = CodeA * CodeB * CodeC;
// print the declared Product and Sum on the screen
std::cout << std::endl;
std::cout << "Es sind immer 3 Ziffern fuer den Code\n";
std::cout << "Die Summe der Ziffern ergibt: " << CodeSum << std::endl;
std::cout << "Das Produkt der Ziffern ergibt: " << CodeProd << std::endl;
// Abfrage der Spielereingaben
int GuessA, GuessB, GuessC;
std::cout << std::endl << "Der Code: ";
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// PrĂźfen ob Spielereingaben korrekt sind
if (GuessSum == CodeSum && GuessProduct == CodeProd)
{
std::cout << "\nKorrekt, die Tuer geht auf,\n du gelangst ins naechste Level";
return true;
}
else
{
std::cout << "\nLeider der falsche Code, probiere es erneut";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty)
// hardcoded true bedingt, dass Spiel immer weiterläuft bis man Ctrl+C drßckt
// true, Wenn Vergleich LevelDifiiculty == Maxdifficulty,
// false endet Programm mit maximaler Schwierigkeit bei return 0;
{
bool bLevelComplete = PlayGame(LevelDifficulty); // speichert, ob Spieler das Level geschafft hat (true) oder nicht (false) und ruft PlayGame() auf
std::cin.clear(); //clears any errors
std::cin.ignore(); // dicards the buffer
if (bLevelComplete) // Ohne == wird Bedingung automatisch true gesetzt: bLevelComplate == true
{
++LevelDifficulty; //LevelDifficulty + 1
}
}
std::cout << "Glueckwunsch! Du bist drin und kannst die Geheimdaten herunterladen...";
return 0;
}
I learned some Cpp as a hobby a few years ago, I build the TripleX game before completing section 2. I was happy to see that for the most part my logic followed along with the course and that I was able to remember so much from awhile ago. I would change a few things now that I completed section 2 but I donât think it was that bad for a first attempt.
#include <iostream>
#include <cstdlib> // For std::rand() and std::srand()
#include <ctime> // for std::time()
#include <string> // For std::string()
int GetRandomNumber(int min, int max) // Get a random number for codes
{
static constexpr double fraction{ 1.0 / (RAND_MAX + 1.0) };
return min + static_cast<int> ((max - min + 1) * (std::rand() * fraction));
}
bool Hacking(int a, int b, int c, int level) // The game function
{
int multi{ a * b * c };
int add{ a + b + c };
int d{ 0 };
int e{ 0 };
int f{ 0 };
int tempmulti{ 0 };
int tempadd{ 0 };
std::cout << "Enter Story here: Level " << level << std::endl;
std::cout << "There are three numbers in the code" << std::endl;
std::cout << "The codes multiply to give " << multi << std::endl;
std::cout << "The codes add to give " << add << std::endl;
while (true)
{
std::cout << "Enter the three code numbers :";
std::cin >> d;
std::cin >> e;
std::cin >> f;
tempmulti = d * e * f;
tempadd = d + e + f;
if (std::cin.fail())
{
std::cout << "Please enter only 3 numbers" << std::endl;
std::cin.clear();
std::cin.ignore(32767, '\n');
continue;
}
else
{
std::cin.ignore(32767, '\n');
break;
}
}
if (tempadd == add)
{
if (tempmulti == multi)
{
return true;
}
}
return false;
}
int main()
{
std::srand(static_cast<unsigned int>(std::time(nullptr)));
bool win = true;
int min = 2;
int difficulty{ 3 };
int difficultIncrease{ 3 };
int levels{ 3 };
bool test;
for (int i = 1; i <= levels; ++i)
{
test = Hacking(GetRandomNumber(min, difficulty), GetRandomNumber(min, difficulty), GetRandomNumber(min, difficulty), i);
if (test)
{
difficulty = difficulty + difficultIncrease;
}
if (!test)
{
std::cout << "You lose";
break;
}
}
if (test)
{
std::cout << "You Win!!!";
}
}
Awesome job everyone!
#include
#include
void PrintIntro(int Difficulty)
{
if(Difficulty==1)
{
std::cout << "\n\nShe is the love of your life, do anything to save her!\n";
std::cout << "Enter the right the code, to unlock the doors to reach her!\n\n";
}
std::cout<<std::endl;
std::cout<<std::endl;
std::cout<<"Door ------> "<<Difficulty;
}
bool PlayGame(int Difficulty)
{
PrintIntro(Difficulty);
std::cout<<std::endl;
std::cout<< " There are 3 numbers in the code! ";
const int CodeA = rand()% Difficulty+Difficulty+1;
const int CodeB = rand()% Difficulty+Difficulty;
const int CodeC = rand()% Difficulty+Difficulty;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
std::cout<< "\n These codes add up to: "<<CodeSum;
std::cout<<"\n And the product of these codes is: "<<CodeProduct ;
std::cout<<std::endl;
int GuessA, GuessB, GuessC ;
std::cin>>GuessA;
std::cin>>GuessB;
std::cin>>GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if (GuessProduct == CodeProduct && GuessSum == CodeSum )
{
if(Difficulty<5)
{
std::cout<<"\n You have opened this door, Proceed to the next one...! ";
}
return true;
}
else
{
std::cout<<"\n You lost! try again! ";
return false;
}
}
int main()
{
srand(time(NULL));
int LevelDifficulty = 1;
const int MaxLevel = 5;
while(LevelDifficulty <= MaxLevel)
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if(bLevelComplete)
{
++LevelDifficulty;
}
else
{
if(LevelDifficulty==5)
{
--LevelDifficulty;
}
}
}
std::cout<<std::endl;
std::cout<<"\nGOOD JOB, YOU REACHED HER !!!";
return 0;
}
im kinda proud
Hereâs my code so far!
#include <iostream>
void PrintIntroduction(int Difficulty)
{
// Prints intro messages to the terminal.
std::cout << "\n\n XX XX XX XX XX XX\n";
std::cout << " XX XX XX XX XX XX\n";
std::cout << " XX XX XX XX XX XX\n";
std::cout << " XX XX XX\n";
std::cout << " XX XX XX XX XX XX\n";
std::cout << " XX XX XX XX XX XX\n";
std::cout << " XX XX XX XX XX XX\n";
std::cout << "You are attempting to break into your lover's phone...\n";
std::cout << "Locking mechanism level " << Difficulty;
std::cout << "\nEnter the correct codes to continue...\n\n";
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
// Declare three 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;
// Prints CodeSum and CodeProduct to the terminal.
std::cout << "There are three numbers in the code";
std::cout << "\nThe codes add up to: " << CodeSum;
std::cout << "\nThe codes multiply to: " << 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 << "\nYou have cracked this level of security!";
return true;
}
else
{
std::cout << "\nWrong code, try again.";
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(); // clears any errors
std::cin.ignore(); // discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "\nYou have broken in. Who knows what secrets you will unearth!";
return 0;
}
Added a switch
#include<iostream>
void PrintIntroduction(int Difficulty)
{
// Print welcome messages to the terminal
std::cout << "\n" << std::endl;
std::cout << R"(
_ _ _ __
| | | | (_) / _|
| |_| |__ _ ___| |_
| __| '_ \| |/ _ \ _|
| |_| | | | | __/ |
\__|_| |_|_|\___|_| )" << std::endl;
std::cout << "You are thief breaking into a level " << Difficulty;
std::cout << " international bank's safe...\nEnter the correct code to continue...\n" << std::endl;
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
// Declare 3 number code
const int CodeA = rand();
const int CodeB = rand();
const int CodeC = rand();
int CodeSum = CodeA + CodeB + CodeC;
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::endl;
std::cout << "+ The codes add-up to: " << CodeSum << std::endl;
std::cout << "+ The code multiplies to give: " << CodeProduct << std::endl;
// Store player's guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC ;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// Check if the player's guess is correct
if(CodeSum == GuessSum && CodeProduct == GuessProduct)
{
switch (Difficulty)
{
case 1:
std::cout << "Congrats, You have reached the safety deposits safe, behind the next door is where you find 50 Million Dollars" << std::endl;
break;
case 2:
std::cout << "impressive, You have reached the Money's safe, behind the next door is where you find 500 Gold Bars" << std::endl;
break;
case 3:
std::cout << "superb, You have reached the Gold's safe, behind the next door is where you find diamonds" << std::endl;
break;
case 4:
std::cout << "HolyShit, diamonds is a code name to the blackbox containing the governments and politicians secrets\n";
std::cout << "This will get you more money than any previous safe's if you sell it in the blackmarket but it will endanger your existance, proceed with caution" << std::endl;
break;
default:
std::cout << "Invalid entry, you don't have much time" << std::endl;
break;
}
return true;
}
else{
std::cout << "The FBI caught you, you are going to prison!" << std::endl;
std::cout << "Your mission now is to jailbreak and continue where you left off" << std::endl;
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxLevel = 4;
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)
{
//increase level difficulty
++LevelDifficulty;
}
}
std::cout << "You are now the greatest and richest thief in history!!!!!!" << std::endl;
return 0;
}
#include <iostream>
void PrintIntroduction(int Difficulty)
{
//printing intro,objectives and warnings to the terminal
std::cout << "\n\nYour phone has been stolen. to get it you have to reach the 3rd location.\n";
std::cout << "you have to open a box. It has a 3 digit combination code lock. to find the code you have to solve a question of difficulty level:" << Difficulty;
std::cout << "\nAnd 'REMEMBER' you have only ONE try FAIL AND FORGET ABOUT YOUR PHONE!!!!\n\n";
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
//declaring the 3 digit code
const int CodeA = rand();
const int CodeB = rand();
const int CodeC = rand();
//declaring CodeSum and CodeProduct of the code
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//printing clues to the terminal
std::cout << "There are 3 numbers in the code.\n";
std::cout << "\nThe sum of the codes add up to: " << CodeSum;
std::cout << "\nThe 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 << "\nCongrates you figured out the code so lets get going :)";
return true;
}
else
{
std::cout << "\nWell Done! You suck and you'll never get your phone back. Retry Level??";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxDifficulty = 3;
while(LevelDifficulty <= MaxDifficulty)// Loop Game Until All Levels Are Complete
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();//clears any errors
std::cin.ignore();//discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "\n\nWOW!! I can't belive you completed my game. So you know that I said you'll get your phone if you entered the correct code so here It is!\n";
//Just a design for the victory message
std::cout << " PHONEPHONEPHONEPHONEPHONE \n";
std::cout << "PHONEPHONEPHONEPHONEPHONEPHONE\n";
std::cout << "PH ON\n";
std::cout << "EP HO\n";
std::cout << "NE PH\n";
std::cout << "ON EP\n";
std::cout << "HO NE\n";
std::cout << "PH ON\n";
std::cout << "EP PHOOOOONE!!!!!!! HO\n";
std::cout << "NE PH\n";
std::cout << "ON EP\n";
std::cout << "HO NE\n";
std::cout << "PH ON\n";
std::cout << "EP PH\n";
std::cout << "ON EP\n";
std::cout << "HO NE\n";
std::cout << "PHONEPHONEPHONEPHONEPHONEPHONE\n";
std::cout << "PHONEPHONE PHONEPHONE\n";
std::cout << "PHONEPHONE PHONEPHONE\n";
std::cout << "PHONEPHONEPHONEPHONEPHONEPHONE\n";
std::cout << " PHONEPHONEPHONEPHONEPHONE \n";
return 0;
}
Everything seems to be coming along nicely I think.
#include <iostream>
void PrintIntroduction(int Difficulty)
{
// Displays story line to the terminal
std::cout << "\n\n\nThe secret is before you after all this time, you can feel it just beyond the " << 6 - Difficulty << " stone doors before you.\n";
std::cout << "However, the ancients did not give away their wisdom easily when they walked this world.\n";
std::cout << "It seems even in death they have not changed their ways.\n";
std::cout << "Solve the puzzles they left behind, and their secrets will be revealed in kind.\n";
std::cout << "_.~\"~._.~\"~._.~\"~._.~\"~.__.~\"~._.~\"~._.~\"~._.~\"~.__.~\"~._.~\"~._.~\"~._.~\"~._\n\n";
}
bool bPlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
// Declare 3 number code
const int CodeA = 4;
const int CodeB = 3;
const int CodeC = 2;
/*
Multiline comment
*/
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// Explain and print the rules and the current CodeProduct and CodeSum of the chosen numbers to the terminal
std::cout << "It is a game of numbers and you must choose three.\n";
std::cout << "Two hints are given for this puzzle for free. It seems as if they add to "<< CodeSum <<" this time.\n";
std::cout << "While they multiply to " << CodeProduct << ".\n";
std::cout << "Now write your answer down and let the ancients see.\n";
//Store the PLayer Guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
//Create the sum and product of the players guess
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
//Check if player Guess is Correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nYou have chosen wisely. The door slides open as you speak the numbers aloud.";
return true;
}
else
{
std::cout << "\nIt seems it is another answer they seek.";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
int const MaxLevel = 5;
while (LevelDifficulty <= MaxLevel) // Loops the game until all levels are completed
{
bool bLevelComplete = bPlayGame(LevelDifficulty);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << " All the ancients knew has been revealed to you. Now it is up to you what you will do with it.";
return 0;
}
Just finished adding the if else statements with the Win-Lose conditions
#include <iostream>
int main()
{
//This section prints text to player on three sperate lines, and sets the storyline.
std::cout << "++ SCANNING LIFE SIGNS ++";
std::cout << std::endl;
std::cout << "++ ADEPTUS ASTARTES CONFIRMED ++";
std::cout << std::endl;
std::cout << std::endl;
std::cout << "Welcome, Astartes. Input Code to Access Armory Door:";
//Here we've defined the integers, and made the constant so as not to be changed
const int CodeA = 3;
const int CodeB = 2;
const int CodeC = 4;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//This section prints the sum and product integers on two seperate lines
std::cout << std::endl;
std::cout << "++ Code requires three digits" << " ++" << std::endl;
std::cout << "++ Digits add-up to: " << CodeSum << " ++" << std::endl;
std::cout << "++ Digits multiply to give: " << CodeProduct << " ++" << std::endl;
//Initializing and programming player input
int InputA, InputB, InputC;
std::cout << std::endl;
std::cout << "++ Input code: ";
std::cin >> InputA;
std::cin >> InputB;
std::cin >> InputC;
//Initializing Player input sum and product values
int InputSum = InputA + InputB + InputC;
int InputProduct = InputA * InputB * InputC;
//Win-Lose condition statements
if (InputSum == CodeSum && InputProduct == CodeProduct)
{
std::cout << std::endl;
std::cout << "Access Granted";
}
else
{
std::cout << std::endl;
std::cout << "Access Denied";
}
return 0;
}
My work after completing Section 27:
#include <iostream>
void PrintIntroduction() // Title screen with intro text
{
std::cout << "\n\n ________\n";
std::cout << "VVVVVVVVVVVVVVVVVVVVVVVVVVV ( ) VVVVVVVVVVVVVVVVVVVVVVVVVVV\n";
std::cout << " VVVVVVVVVVVVVVVVVVVVV ( X X ) VVVVVVVVVVVVVVVVVVVVV\n";
std::cout << " VVVVVVVVVVVV | ^^ | VVVVVVVVVVVV\n";
std::cout << " VVVV < > VVVV\n\n";
std::cout << " ||||\n\n";
std::cout << " TRIPLE X\n\n";
std::cout << "++ SCANNING LIFE SIGNS ++\n";
std::cout << "++ ADEPTUS ASTARTES CONFIRMED ++\n\n";
}
void RequestAction(int LevelDifficulty) // Request Action function, seperated to avoid repeating PrintIntroduction function
{
std::cout << "Welcome, Astartes. Input Code to Access Armory Door "<< LevelDifficulty << ":";
}
bool PlayGame(int LevelDifficulty) // Game function
{
RequestAction(LevelDifficulty);
// Defined the integers, and made constant so as not to be changed
const int CodeA = 3;
const int CodeB = 2;
const int CodeC = 4;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// This section prints the sum and product integers on two seperate lines
std::cout << "\n++ Code requires three digits ++\n";
std::cout << "++ Digits add-up to: " << CodeSum << " ++\n";
std::cout << "++ Digits multiply to give: " << CodeProduct << " ++\n\n";
// Initializing and asking for player input values
int InputA, InputB, InputC;
std::cout << "++ Input code: \n";
std::cin >> InputA >> InputB >> InputC;;
int InputSum = InputA + InputB + InputC;
int InputProduct = InputA * InputB * InputC;
// Win-Lose strings
if (InputSum == CodeSum && InputProduct == CodeProduct)
{
std::cout << "\n\n\nACCESS GRANTED... Opening Door " << LevelDifficulty << "\n\n"; // Print door being opened
return true;
}
else
{
std::cout << "\n\n\nACCESS DENIED... Try Again. \n";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
PrintIntroduction();
while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels are completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // Clear errors
std::cin.ignore(); // Remove incorrect input
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "++ All Doors Accessed ++\n";
std::cout << "++ Congratulations Astartes, you are ready for battle ++\n";
std::cout << "++ EMPEROR PROTECTS ++\n";
return 0;
}
Here they are my first C++ code, XD
Triple X game in a decrypt the code version.
#include <iostream>
#include <string>
#include <random>
#include <ctime>
#include <vector>
void PrintIntro()
{
std::cout << R"(
.-------. ______
/ o /| /\ \
/_______/o| /o \ o \
| o | | / o\_____\
| o |o/ \o /o /
| o |/ \ o/ o /
'-------' \/____o/
)";
// Print welcome message to the terminal.
std::cout << std::endl << std::endl;
std::cout << "You are a alchemy student and when you were cleaning you poured the dust mix,\n";
std::cout << "now you have to replace it before the teacher finds out.\n\n";
std::cout << "Pour the combination of four ingredients in their corresponding order...\n\n";
std::cout << "The ingredients in the table are: " << std::endl;
std::cout << " 'R (rust iron)', 'G (gold)', 'B (bronce)', 'Y (yttrium)'...\n" << std::endl;
}
std::string GenerateCode()
{
srand((unsigned)time(0));
std::string CodeList[] = {"R","G","B","Y" };
// Generate randome index 0 - 3
int FirstIndex = (rand() % 4);
int SecondIndex = (rand() % 4);
int ThirdIndex = (rand() % 4);
int FourthIndex = (rand() % 4);
//std::cout << "\n" << FirstIndex << SecondIndex << ThirdIndex << FourthIndex;
std::string FirstCode = CodeList[FirstIndex];
std::string SecondCode = CodeList[SecondIndex];
std::string ThirdCode = CodeList[ThirdIndex];
std::string FourthCode = CodeList[FourthIndex];
// Combine code
std::string CodeMix = FirstCode + SecondCode + ThirdCode + FourthCode;
return CodeMix;
}
std::string PlayGame()
{
std::cout << "\n\nAdd the materials in your order\n";
std::string Guess0, Guess1, Guess2, Guess3;
std::cin >> Guess0 >> Guess1 >> Guess2 >> Guess3;
std::string GuessCode = Guess0 + Guess1 + Guess2 + Guess3;
return GuessCode;
}
bool DecodeGuess(std::string Code, std::string Guess)
{
std::cout << "Code: " << Code;
std::cout << "\nGuess: " << Guess;
int PositionCorrect = 0;
int MatCorrect = 0;
for (int i = 0; i < 4; i++)
{
//std::cout << "\niteration: " << i;
//std::cout << "\nIndexCode: " << Guess[i];
// Check if "materials in guess" are in the Code
for (int x = 0; x < 4; x++)
{
if (Guess[i] == Code[x])
{
++MatCorrect;
break;
}
}
// Check for correct position
if (Guess[i] == Code[i])
{
++PositionCorrect;
}
}
std::cout << "\n\nCorrect materials in the combination: " << MatCorrect;
std::cout << "\nCorrect order: " << PositionCorrect;
if (PositionCorrect == 4)
{
return true;
}
return false;
}
int main()
{
// Intro
PrintIntro();
// Get Material order
std::string CodeMix;
CodeMix = GenerateCode();
std::cout << "\n" << CodeMix;
int PlayerGuessAttempt = 0;
int const MaxTrys = 5;
std::string GuessAttempt;
while (PlayerGuessAttempt <= MaxTrys)
{
GuessAttempt = PlayGame();
bool bLevel = DecodeGuess(CodeMix, GuessAttempt);
if (bLevel)
{
std::cout << " Congratulations!!, the master will never know...";
return 0;
}
++PlayerGuessAttempt;
}
return 0;
}