TripleX - Bad Phone Security Ideas

Sometimes, you just want it to be a pain to get into your phone. I had fun with this one. Sorry for the dark humor.

#include <iostream>
#include <ctime>

void PrintIntroduction(int MaxDifficulty)
{
  // Cool Ascii Art
  std::cout << R"(
              _.._           
     __.--"" __ ""--.__    
   .'//   .-"  "-.   \\`,  
  : :'  .'.  :;  ,`.  `; ; 
 /; ;  /  T. $$ ,P  \  : : 
/: :  ;    T.:;,P    :  ; ;
)| | :      `  '      ; | |
`j | :.--------------.: | |
 ; ; |                | : :
 ; ; |                | : :
 | | |                | | |
 | | |                | | |
 : : |                | ; ;
 : : :________________: ; ;
  ; ;__    _...._    __: : 
  | ;  "-./ ,--, \,-"  : | 
  | '._   \ ;  : /   _.' | 
  :  __`-. `."",' .-'__  ; 
   ;`.__> `.J__L.' <__.':  
   ;.--._   .--.   _.--,:  
   |`.__.' `.__.' `.__.'|  
   |.--._   .--.   _.--,|  
   |`.__.' `.__.' `.__.'|  
   |.--._   .--.   _.--,|  
   ;`.__.' `.__.' `.__.':  
  : .--._   .--.   _.--, ; 
  ; `.__.' `.__.' `.__.' : 
  ;                      : 
  '--..__          __..--' 
         """"""""""       )"
            << "\n";

  // Story intro to set game atmosphere
  std::cout << "You figured that anyone that breaks into your phone should be lucky enough to do so.\n";
  std::cout << "You didn't consider yourself to be part of the people that will break into your phone, yet here you are.\n";
  std::cout << "You'll have to enter the correct codes " << MaxDifficulty << " times to continue...";
}

bool PlayGame(int LevelDifficulty, int MaxDifficulty)
{

  // Declare 3 number code
  const int CodeA = rand() % LevelDifficulty + LevelDifficulty;
  const int CodeB = rand() % LevelDifficulty + LevelDifficulty;
  const int CodeC = rand() % LevelDifficulty + LevelDifficulty;

  const int CodeSum = CodeA + CodeB + CodeC;
  const int CodeProduct = CodeA * CodeB * CodeC;

  // Print CodeSum and CodeProduct to the terminal
  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;

  // Initialize Our Guesses
  int GuessA, GuessB, GuessC;

  // Prompt the User for their Guesses
  std::cout << "\nEnter the 3 numbers to match: ";
  std::cin >> GuessA >> GuessB >> GuessC;

  // Calculate the Guess Sum and Product and initilize that to their variables
  int GuessSum = GuessA + GuessB + GuessC;
  int GuessProduct = GuessA * GuessB * GuessC;

  // Check if the player guess is correct
  if ((GuessSum == CodeSum) && (GuessProduct == CodeProduct))
  {
    // Since we're only playing the introduction once
    // Progress completion is tracked by completing levels instead.
    if (LevelDifficulty == MaxDifficulty)
    {
      std::cout << "\nYou have finally, successfully unlocked your phone!";
      std::cout << "\nYou check the date to find that it is March 2020.";
      std::cout << "\nYou quite understandably throw your phone across the room.";
      std::cout << "\nYou hear your neighbor screaming next door. You join them.";
    }
    else
    {
      std::cout << "\nOne level down, only " << MaxDifficulty - LevelDifficulty << " left to go!";
    }
    return true;
  }
  else
  {
    std::cout << "\nYou phone remains locked. You'll have to keep trying.";
    std::cout << "\nOne level failed, still only " << MaxDifficulty - LevelDifficulty << " left to go.";
    return false;
  }
}

int main()
{
  int LevelDifficulty = 1;
  int MaxDifficulty = 10;
  srand(time(NULL));

  PrintIntroduction(MaxDifficulty); // I only want to play the introduction once for this game.
  while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels are completed
  {
    bool bLevelComplete = PlayGame(LevelDifficulty, MaxDifficulty);
    std::cin.clear();   //Clears any errors
    std::cin.ignore();  // Discards the Buffer

    if (bLevelComplete)
    {
      // Increase the level difficulty
      ++LevelDifficulty;
    }
  }

  return 0;
}

1 Like

I mean why not right :man_shrugging:

1 Like

Privacy & Terms