Game Development

Game Development – Selfdestruct

I spent most of the day on Saturday 5/4/2019 going through the next lesson on my C++ game development course on Udemy.

https://community.gamedev.tv/t/selfdestruct-my-own-customized-version-of-lesson-2-base-on-triplex/104886

 


// |**********************************************************************
// * Project : Lesson 2 based on TripleX course.
// *
// * Program name : selfdestruct
// *
// * Author : morggin@gmail.com (Billy F. Jameson Jr.)
// *
// * Date created : 5/4/2019
// *
// * Purpose : Small C++ number guessing game.
// *
// *
// *
// *
// * Revision 1.1 made on 5/4/2019 to fix spelling errors.
// *
// |**********************************************************************
#include <iostream>
#include <ctime>

const int MaxLevel=5;
int FailedCode=0;
void SelfdestructSit()
{
// Print situation to the terminal
std::cout << “You are onboard a space ship.\n”;
std::cout << “You are jarred awake by a dreadful sounding alert.\n”;
std::cout << “Along with the blaring sirens, an automated message is broadcast through out the ship.\n”;
std::cout << “The self destruct sequence has been activated. Please proceed to an escape pod.\n”;
std::cout << “Desperately you seek out the nearest escape pod.\n”;
std::cout << “You find yourself suffering from apoplexy as a futile search has revealed all 24 escape pods have been jettisoned.\n”;
std::cout << “You realize you have to abort the self destruct seqence.\n”;
std::cout << “Frantically you scramble to the bridge of the ship and take a seat at the main terminal.\n”;
return;
}

void PrintTerminal(int Difficulty)
{
std::cout << “\n\nThe main terminal flickers to life\n”;
std::cout << “Please enter Security Sequence: ” << Difficulty << ” of ” << MaxLevel << “\n”;
}

bool PlayGame(int Difficulty)
{
PrintTerminal(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 CodeProd = CodeA * CodeB * CodeC;

// Print CodeSum and CodeProd to the terminal
std::cout << “\n\n”;
// std::cout << ” – code is “<< CodeA <<” “<< CodeB <<” “<< CodeC <<” -\n”;
std::cout << “+There are 3 codes in the security sequence\n”;
std::cout << “+The security codes add up to: “<< CodeSum <<“\n”;
std::cout << “+The security codes multiply to give: ” << CodeProd <<“\n”;

// Store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;

int GuessSum = GuessA + GuessB + GuessC;
int GuessProd = GuessA * GuessB * GuessC;

// Check if the players guess is correct
if (GuessSum == CodeSum && GuessProd == CodeProd)
{
std::cout << “\n\n+You have deactivated the self destruct code for sequence: ” << Difficulty << “\n”;
return true;
}
else
{
std::cout << “\n\n YOU FAILED TO ENTER THE CORRECT SECURITY CODE\n\n”;
++FailedCode;
return false;
}
}

int main()
{
srand(time(NULL)); // Create new random sequence based on time of day.

int LevelDifficulty = 1;
SelfdestructSit();

while (LevelDifficulty <= MaxLevel) // Loop the game till all codes are found or ship is destroyed.
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // Clears any errors.
std::cin.ignore(); // Discards the buffer.

if (bLevelComplete)
{
++LevelDifficulty;
}
if (FailedCode == 3) // Game ends in self destruction.
{
std::cout << ” The terminal window shuts off and the keyboard becomes unresponsive as intense heat begins to build.\n\n”;
std::cout << “In a bright blinding flash *** THE SHIP EXPLODES *** spreading your remains all over the cosmos.\n\n”;
std::cout << ” GAME OVER MAN \n\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 << ” * * * *G*A*M*E* * * * * * *O*V*E*R* * * *\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::cin.get();
exit(0);
}

}
std::cout << “\n*** Great work! You saved the ship! ***\n”;
std::cout << “You dock at the next space station and stroll into the nearest seedy tavern \”The Boastful Blaster\” for a nerve calming drink!\n”;
std::cin.get();
return 0;
}