TripleX: The Sci-fi "Hack" Thriller

Here is my TripleX game. I added a few bits of code here and there to accommodate the length of my program and the specific features I wanted to see in it. I made many more functions as practice. Maybe some were not needed or a little messy?

One of these functions was my “proceed” function. Since I do not know how to simply “Press Enter to Continue”, and did not look it up, I decided to work in a “Press any number and then enter to continue” method. I found it useful pasting my proceed function to break up some of my story and to add some suspense while saving my code some space.

I also added a switch- I had come into contact with these before and wanted to try one out. I used a switch in the “if” statement that moderated the fail or success outcomes of the puzzle in the PlayGame function. I added 5 cases so to produce 5 messages which correspond to the 5 different levels present in the game. This was to help create a sense of progression and increasing achievement with each successful security hack.

I was able to utilize the “int” trick to keep track of what level the player was on and displaying the right message at the completion of each level.

Here is my code:

[Edited] - Sorry for posting pictures rather than code, I did not think of using the preformatted text option. So here is the code below- pictures not needed!

#include <iostream>
#include <ctime>// using as a seed to make random numbers more random.

void PressToContinue()
{
  int Proceed;
  std::cout << "Press any number and hit \"enter\" to continue";
      std::cout << "\n";
      std::cin >> Proceed;
      std::cout << "\n";
}

void SpaceStationPicture()// picture of a spacestation
{
  std::cout << "       \n\n"
  <<"                       }--O--{\n"
  <<"                         [^]\n"
  <<"                        /ooo\\\n"
  <<"        ______________:/o   o\\:______________\n"
  <<"      |=|=|=|=|=|=|:A|\":|||:\"|A:|=|=|=|=|=|=|\n"
  <<"       ^\"\"\"\"\"\"\"\"\"\"\"\"\"\"!::{o}::!\"\"\"\"\"\"\"\"\"\"\"\"\"\"^\n"
  <<"                       \\     /\n"
  <<"                        \\.../\n"
  <<"             ____       \"---\"       ____\n"
  <<"            |\\/\\/|=======|*|=======|\\/\\/|\n"
  <<"            :----\"       /-\\       \"----:\n"
  <<"                        /ooo\\\n"
  <<"                       #|ooo|#\n"
  <<"                        \\___/\n";     

  std::cout << "\nArt: https://www.asciiart.eu/space/satellites"
           <<"\n\n         !!!!!!!!!!!!  TRIPLE X    !!!!!!!!!!\n\n";  

  PressToContinue();          
}

void PrintIntroduction()
{
 // The point of the Game: sets up story/reason
    std::cout << "\n\nYou are a Master Hacker known to your employers as TripleX\n"
              << "You are known for taking risky jobs often shunned by other hackers.\n"
              << "Recently, you and a team of veteran soldiers were hired to survey an\n"
              << "ancient science oribital research station, one only known to the employer:\n"
              << "you don't ask how, save for how much he's willing to compensate your time.\n\n"

              << "While your employer's intel is sure that this facility is devoid of any life-forms,\n"
              << "you have a small team of veteran soldier as \'insurance\' against anything inorganic.\n"
              << " Besides, your expertise is hacking terminals, not robots.\n\n"

              << "Your mission is to search the station's databanks for any information\n"
              << "concerning its former inhabitants, their culture, what discoveries they\n"
              << "may have made, or technological information of any sort.\n\n"
                
              << "This is considered 'piece work': after you bypass one level of security, you will\n"
              << "download that block of data, transfer it to your employer, and he will immediately transfer\n"
              << "2 million credits into your account. If you manage to retrieve all possible data, your pay will be doubled.\n"
              << "Not bad, even with the horrible inflation\n\n" 

              << "The employer had the goodness to remind you that the data is absolutely \n"
              << "irreplacable, and that this benefit does not extend to 'Master Hackers'. \n"
              << " But the danger pay is good: if you survive the danger you get paid.\n\n";
              
    PressToContinue();    
    
    std::cout << " \"Look on the bright side\", you say to yourself, \"for each block I access they will\n"
              << "automatically tranfer millions of credit into my account.\" \n\n"

              << "\"Worst case senerio? I won't be around to enjoy it\", you grin.\n\n";
    
    PressToContinue();    

    std::cout << "There appears to be no life on this station, but the power is still functional.  \n" 
              << "You and your team soon make it to what appears to be the main security terminal\n"
              << "and begin trying to hack into its systems. In a few short minutes you discover that\n" 
              << "the ship was indeed abandoned and that the ship was only running on emergency power.\n"
              << "However, your cursory perusal revealed an important 'minor' obstacle between you and\n "
              << "the databanks that even the best hackers could have missed: the entire spacestation was\n"
              << "rigged to explode should the wrong codes be entered. A precaution against looters or rivals.\n\n"

              << "This is going to be a blast...\n\n"; 
       
    PressToContinue();    

    std::cout << "You begin to apply your trade...\n\n";

    std::cout << "Your hacking tool manages to crack large segments of the code, but due to the ravages of time\n"
              << "some parts of code are corrupt and indecipherable sections. You tool begins blinking red, you cannot\n"
              << "proceed any further without triggering the security system. There are three characters are left in each\n"
              << "code, with nothing but clues to indicate what the rest of it might be... not good.\n\n"
              << "Time to do this this hard way...\n\n"
              << "\"Worst case scenerio indeed\", you say to yourself.\n\n";
    
    
    PressToContinue();
   }
// this is the separate hacking message. It is separate from the intro because of the intro's length
// it would be too much to repeat should the player die.
void HackingMessage(int Difficulty)
{
   std::cout << "Please enter your Level " << Difficulty << " Security code\n"
              << "to the terminal to continue...\n\n";
}
// below is the success messages when the terminal is successfully hacked, they could have been consolidated into 
// the PlayGame bool function, within the if statement.
void HackingWinOne()
{
  std::cout << "\nYou hacked into the first level of security.\n\n"
            << "There are reports detailing the people who lived here, their culture,\n"
            << "their general level of technology, other bits of information.\n\n"
            << "Your account recieves its first injection of credits\n\n";
}

void HackingWinTwo()
{
  std::cout << "\nYou hacked into the second level of security.\n\n"
            << "You discover that these people were fairly advanced in comparison to your own.\n"
            << "This station was a science station dedicated to secret technological advances,\n"
            << "including wormhole stabilization techniques.\n\n"
            << "You recieve your second injection of credits.\n\n";
}
void HackingWinThree()
{
  std::cout << "\nYou hacked into the third level of security.\n\n"            
            << "You discover that this base was a science station of some sort. It seemed to focus\n"
            << "on secret experimental technologies. One of these was an advanced wormhole stabilizer.\n\n" 
            << "You recieve your third injection of credits\n\n";
}

void HackingWinFour()
{
  std::cout << "\nYou hacked into the fourth level of security\n\n"
            << "You discover the reason behind the station's abandonment: its proto-warp stabalizer malfunctioned.\n"
            << "The unit began to overload causing the wormhole to expand too rapidly to contain. The files suggest\n"
            << "it was connected to the other science facilities and it was beginning to drain power from them before\n"
            << "they were closed from their respective sides. Everyone within this facility quickly abandoned the station.\n\n"
            << "You recieve your fourth injection of credits\n\n";

  PressToContinue();

  std::cout << "\"Almost done\", you say under your breath.\n"
            << "One of your teammates overheard you and asked \"we already have most of the pay, why not leave?\""
            << "\"Did our employer hire us to quit or because he believed we could get the job done? It is all or\n"
            << "nothing, soldier!\"\n\n"
            << "The soldier grumbles a little, the rest are resolute.\n\n"
            << "\"Don't mind Big Tom,\" answers one of the other soldiers, \"He tends to complain alot, but\n"
            << "I guarantee you he will have your back.\n\n"
            << "\"Because he has quick reflexes,\" retorts another, \"he'll catch it when this place explodes!\"\n\n"
            << "The other soldiers laugh, poking Big Tom in the ribs, while some of the more \"civilized\"\n"
            << "members cringe at the thought. You wait until a somber mood reasserted itself. Why not let them\n"
            << "have a little laugh at your expense? It might be their last...\n\n";

                       
}
void HackingWinFive()
{
  std::cout << "\nYou hacked into the fifth level of security.\n\n"
            << "Upon digging further  you discover that this station was the head station of a series of other space stations and operations.\n"
            << "You pull up many space chart depicting unknown areas of space, with the locations of the other facilities.\n"
            << "You also ascertain from some charts that this facility is no where near its original location.\n"
            << "This suggests that the facility had warped after the experiments accident, yet was left mostly intact.\n"
            << "It jump must have fried most of the security systems save one: the self-destruction sequence.\n"
            << "You recieve your fifth injection of credits\n\n";
}
/* I placed the End Game and Credit Rolls here to clean up space in the actual main function area.
   It also doubles as practice codes, using functions and calling them up elsewhere with the simple
   use of their name*/
   
void EndGame()
{
  std::cout << "You sight in relief. It is finished. \n\n"
            << "\"Done\", you tell your companions, \"all the files have been transfered over\"\n\n"
            << "They too sigh in relief.\n\n"
            << "\"Another bullet dodged boys... this time,\" you say to your team.\n\n";

  PressToContinue();      

  std::cout << "The entire databank has completed downloading to your device and soon you transfer the last bits\n" 
            << "of data to your employer. You notice the number in your account double to 20 million cr.\n\n"
            << "\"Your accounts are being filled up as we speak, and it looks like we are\n"
            << "recieving the bonus as promised.\"\n\n";
      
  PressToContinue();
      
  std::cout << " \"How much were you promised?\" one of them asked.\n\n"
            << "\"Enough to retire early,\" you smile.\n\n"
            << "\"When do you plan on starting?\"\n\n"
            << "You chuckle as you log off the terminal and prepare for departure, \n\n\"Tomorrow.\"\n\n"
            << "*****THE END!*****\n\n";                
      
  PressToContinue();
}

void CreditRoll()
{
   std::cout << "Credits:\n\n"
             << "Story: Zangk\n"
             << "Writer: Zangk\n"
             << "Beginning Art Design: https://www.asciiart.eu/space/satellites\n"
             << "Game Tester: Zangk\n"
             << "Visual Effects: Zangk\n"
             << "Sound Effects: Zangk\n"
             << "Costume Design: Zangk\n"
             << "Concept Artist: Zangk\n"
             << "Producer: Zangk\n"
             << "Humour Advisor: Zangk\n\n"
             << "The End";
}

bool PlayGame(int Difficulty)
{
  HackingMessage(Difficulty);  
  
    /* these are for the 3 numbers for the puzzle game, the sum is added up do give a hint
    what the numbers of the code are.*/

    // declare 3 number code using a rand() and a modulus to limit the random #
    const int CodeA = rand() % Difficulty + Difficulty;
    const int CodeB = rand() % Difficulty + Difficulty;
    const int CodeC = rand() % Difficulty + Difficulty;

    //input sume and product
    
    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    // print CodeSum and CpdeProduct to the terminal
     
    std::cout << "Hacking tool: there are three numbers in the code...\n"
              << "Order does not matter, the tool can manage\n"
              << "The codes add-up to: " << CodeSum << "\n"
              << "The codes multiply to give: " << CodeProduct << "\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 the player guess is correct, if so, displays a different message each level

      if (GuessSum == CodeSum && GuessProduct == CodeProduct) 
    {
      switch (Difficulty)
        {case 1: 
          HackingWinOne();
         break;
        case 2:
          HackingWinTwo();
         break;
        case 3:
          HackingWinThree();
          break;
        case 4:
          HackingWinFour();
          break;
        case 5:
          HackingWinFive();
          break;
        }
     
      PressToContinue();      

      return true;
    }
    else
    {
      std::cout << "\nClearance Code declined, have a nice day.\n\n"
                << "You don't even have time to cry out in horror as the entire spacestation\n"
                << "explodes and you instantly consumed by the raging inferno.\n\n";

      PressToContinue();
      
      std::cout << "Your employer is not very pleased with the results, but what can be done if \n"
                << "even a Master Hacker cannot 'hack' it?\n\n"
                << "****Restarting from last Level achieved****\n\n";
   
      PressToContinue();

      return false;
    }
   
}

int main()
{   
  srand(time(NULL)); // creates random sequence based on the time of day.
  SpaceStationPicture();
  PrintIntroduction();

  int LevelDifficulty = 1;
  const int MaxLevel = 5; // Max amount of Levels before game is done.

  while (LevelDifficulty <= MaxLevel) // 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;
    } 
   
  }
 
   
  EndGame(); 
  CreditRoll();

  return 0;
}

 
1 Like

Wow you did an incredible job!! :fire::fire::fire: How long did it take you?!

I worked in bits and pieces as I went through the course, so while I would have taken a long time, the time was spread throughout the entire section.