Advertisement
NDTurtle

Code

Jul 28th, 2020
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.27 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Hacker : MonoBehaviour
  4.  
  5. {
  6.     // Game config
  7.     string[] level1passwords = { "friend", "neighbor", "home", "password", "123", "qwerty" };
  8.     string[] level2passwords = { "police", "law", "squadcar", "sergeant", "tazer", "donut" };
  9.     string[] level3passwords = { "federal", "machinegun", "fbiopenup", "feds", "prison", "trouble" };
  10.    
  11.     // Game state
  12.     int level;
  13.     int CrackAttempts;
  14.     enum Screen { MainMenu, Password, Win, EasterEgg };
  15.     Screen currentScreen = Screen.MainMenu;
  16.     string password;
  17.  
  18.     // Start is called before the first frame update
  19.    
  20.     void Start()
  21.     {
  22.         ShowMainMenu();
  23.     }
  24.  
  25.     void ShowMainMenu()
  26.     {
  27.         Terminal.ClearScreen();
  28.         Terminal.WriteLine("What would you like to hack into?");
  29.         Terminal.WriteLine(" ");
  30.         Terminal.WriteLine("Press 1 for your neighbors wifi.");
  31.         Terminal.WriteLine("Press 2 for the local police station.");
  32.         Terminal.WriteLine("Press 3 for the FBI.");
  33.         Terminal.WriteLine(" ");
  34.         Terminal.WriteLine("Please enter your selection:");
  35.         currentScreen = Screen.MainMenu;        
  36.     }
  37.  
  38.     void OnUserInput (string input)
  39.     {
  40.         bool isValidLevelNumber = (input == "1" || input == "2" || input == "3");
  41.         if (isValidLevelNumber)
  42.         {
  43.             level = int.Parse(input);
  44.             StartGame();
  45.         }
  46.        
  47.         else if (input == "Menu")
  48.         {
  49.             ShowMainMenu();
  50.             currentScreen = Screen.MainMenu;
  51.         }
  52.  
  53.         else if (currentScreen == Screen.Password)
  54.         {
  55.             Password();
  56.         }
  57.  
  58.         else if (input == "Method0901")
  59.         {
  60.             Terminal.WriteLine("Follow Method0901 on twitch: twitch.tv/METHOD0901");
  61.             currentScreen = Screen.EasterEgg;
  62.         }        
  63.        
  64.         else
  65.         {
  66.             Terminal.WriteLine("Please make a valid selection.");
  67.         }
  68.        
  69.        
  70.  
  71.         void StartGame ()
  72.         {
  73.             Terminal.ClearScreen();
  74.             Terminal.WriteLine("You have chosen level " + level);
  75.             Terminal.WriteLine(" ");
  76.             Terminal.WriteLine("Input 'Menu' or a new level number to");
  77.             Terminal.WriteLine("choose another level.");
  78.             Terminal.WriteLine("Please enter the password: hint: " + password.Anagram());
  79.             currentScreen = Screen.Password;
  80.             switch (level)
  81.             {
  82.                 case 1:
  83.                     int index1 = Random.Range(0, level1passwords.Length);
  84.                     password = level1passwords[index1];
  85.                     level = 1;
  86.                     break;
  87.                 case 2:
  88.                     int index2 = Random.Range(0, level2passwords.Length);
  89.                     password = level2passwords[index2];
  90.                     level = 2;
  91.                     break;
  92.                 case 3:
  93.                     int index3 = Random.Range(0, level3passwords.Length);
  94.                     password = level3passwords[index3];
  95.                     level = 3;
  96.                     break;
  97.                 default:
  98.                     Debug.LogError("Invalid level number.");
  99.                     break;
  100.             }
  101.         }
  102.        
  103.        
  104.  
  105.         void Password()
  106.         {
  107.             if (input == password)
  108.             {
  109.                 DisplayWinScreen();
  110.             }
  111.             else
  112.             {
  113.                 Terminal.WriteLine(" ");
  114.                 Terminal.WriteLine("Password incorrect.");
  115.                 CrackAttempts += 1;
  116.                 Terminal.WriteLine("Failed cracking attempts: " + CrackAttempts);
  117.                 Terminal.WriteLine("Try again:");
  118.                 StartGame();
  119.             }
  120.         }
  121.  
  122.         void DisplayWinScreen()
  123.         {
  124.             currentScreen = Screen.Win;
  125.             Terminal.ClearScreen();
  126.             ShowLevelReward();          
  127.         }
  128.        
  129.         void ShowLevelReward()
  130.         {
  131.             switch (level)
  132.             {
  133.                 case 1:
  134.                     Terminal.WriteLine("You cracked the level " + level + " password!");
  135.                     Terminal.WriteLine(@"
  136. _______  _______
  137. |       ||       |
  138. |    ___||    ___|
  139. |   | __ |   | __
  140. |   ||  ||   ||  |
  141. |   |_| ||   |_| |
  142. |_______||_______|
  143.  
  144. ");
  145.                     break;
  146.                 case 2:
  147.                     Terminal.WriteLine("You cracked the level " + level + " password!");
  148.                     Terminal.WriteLine(@"
  149. _______  _______  _______
  150. |       ||       ||       |
  151. |    _  ||   _   ||    ___|
  152. |   |_| ||  | |  ||   | __
  153. |    ___||  |_|  ||   ||  |
  154. |   |    |       ||   |_| |
  155. |___|    |_______||_______|
  156.                    
  157. ");
  158.                     break;
  159.                 case 3:
  160.                     Terminal.WriteLine("You beat the game!!!");
  161.                     Terminal.WriteLine(@"
  162. _______  _______
  163. |       ||       |
  164. |    ___||____   |
  165. |   |___  ____|  |
  166. |    ___|| ______|
  167. |   |___ | |_____
  168. |_______||_______|
  169.  
  170. ");
  171.                     break;
  172.                 default:
  173.                     Debug.LogError("Invalid level reached. How did we get here...");
  174.                     break;
  175.  
  176.             }
  177.         }
  178.  
  179.  
  180.        
  181.        
  182.     }
  183.    
  184.        
  185.  
  186.    
  187.        
  188. }
  189.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement