Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.32 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Hacker : MonoBehaviour {
  4.  
  5.     // Game configuration data
  6.     const string menuHint = "You may type menu at any time.";
  7.     string[] level1Passwords = { "books", "aisle", "shelf", "password", "font", "borrow" };
  8.     string[] level2Passwords = { "prisoner", "handcuffs", "holster", "uniform", "arrest" };
  9.     string[] level3Passwords = { "starfield", "telescope", "environment", "exploration", "astronauts" };
  10.  
  11.     // Game state
  12.     int level;
  13.     enum Screen { MainMenu, Password, Win };
  14.     Screen currentScreen;
  15.     string password;
  16.  
  17.     // Use this for initialization
  18.     void Start ()
  19.     {
  20.         ShowMainMenu ();
  21.     }
  22.  
  23.     void ShowMainMenu ()
  24.     {
  25.         currentScreen = Screen.MainMenu;
  26.         Terminal.ClearScreen();
  27.         Terminal.WriteLine("What would you like to hack into?");
  28.         Terminal.WriteLine("Press 1 for the local library");
  29.         Terminal.WriteLine("Press 2 for the police station");
  30.         Terminal.WriteLine("Press 3 for NASA!");
  31.         Terminal.WriteLine("Enter your selection:");
  32.     }
  33.  
  34.     void OnUserInput(string input)
  35.     {
  36.         if (input == "menu") // we can always go direct to main menu
  37.         {
  38.             ShowMainMenu();
  39.         }
  40.         else if (currentScreen == Screen.MainMenu)
  41.         {
  42.             RunMainMenu(input);
  43.         }
  44.         else if (currentScreen == Screen.Password)
  45.         {
  46.             CheckPassword(input);
  47.         }
  48.     }
  49.  
  50.     void RunMainMenu(string input)
  51.     {
  52.         bool isValidLevelNumber = (input == "1" || input == "2" || input == "3");
  53.         if (isValidLevelNumber)
  54.         {
  55.             level = int.Parse(input);
  56.             AskForPassword();
  57.         }
  58.         else if (input == "007") // easter egg
  59.         {
  60.             Terminal.WriteLine("Please select a level Mr Bond!");
  61.         }
  62.         else
  63.         {
  64.             Terminal.WriteLine("Please choose a valid level");
  65.             Terminal.WriteLine(menuHint);
  66.         }
  67.     }
  68.  
  69.     void AskForPassword()
  70.     {
  71.         currentScreen = Screen.Password;
  72.         Terminal.WriteLine("We are connecting you to " + level);
  73.         Terminal.WriteLine("Enter password. Hint: " + password.Anagram());
  74.         PasswordGenerator();
  75.     }
  76.  
  77.     void PasswordGenerator()
  78.     {
  79.         switch (level)
  80.         {
  81.             case 1:
  82.                 int index = Random.Range(0, level1Passwords.Length);
  83.                 password = level1Passwords[index];
  84.                 break;
  85.  
  86.             case 2:
  87.                 int index2 = Random.Range(0, level2Passwords.Length);
  88.                 password = level2Passwords[index2];
  89.                 break;
  90.  
  91.             case 3:
  92.                 int index3 = Random.Range(0, level3Passwords.Length);
  93.                 password = level3Passwords[index3];
  94.                 break;
  95.  
  96.            
  97.             default:
  98.                 Debug.Log("Invalid Level boi");  //In case, if I will mess up with code too much
  99.                 break;
  100.         }
  101.     }
  102.  
  103.     void CheckPassword(string input)
  104.     {
  105.         if (input == password)
  106.         {
  107.             DisplayWinScreen();
  108.         }
  109.         else
  110.         {
  111.             AskForPassword();
  112.         }
  113.     }
  114.  
  115.     void DisplayWinScreen()
  116.     {
  117.         currentScreen = Screen.Win;
  118.         Terminal.ClearScreen();
  119.         ShowLevelReward();
  120.         Terminal.WriteLine(menuHint);
  121.     }
  122.  
  123.     void ShowLevelReward()
  124.     {
  125.         switch (level)
  126.         {
  127.             case 1:
  128.                 Terminal.WriteLine("Have a book...");
  129.                 Terminal.WriteLine(@"
  130.    _______
  131.   /      //
  132.  /      //
  133. /_____ //
  134. (______(/          
  135. "
  136.                 );
  137.                 break;
  138.             case 2:
  139.                 Terminal.WriteLine("You got the prison key!");
  140.                 Terminal.WriteLine(@"
  141. __
  142. /0 \_______
  143. \__/-=' = '        
  144. "
  145.                 );
  146.                 Terminal.WriteLine("Play again for a greater challenge.");
  147.                 break;
  148.             case 3:
  149.                 Terminal.WriteLine(@"
  150. _ __   __ _ ___  __ _
  151. | '_ \ / _` / __|/ _` |
  152. | | | | (_| \__ \ (_| |
  153. |_| |_|\__,_|___)\__,_|
  154. "
  155.                 );
  156.                 Terminal.WriteLine("Welcome to NASA's internal system!");
  157.                 break;
  158.             default:
  159.                 Debug.LogError("Invalid level reached");
  160.                 break;
  161.         }
  162.     }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement