Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class Hacker : MonoBehaviour {
- // Game configuration data
- const string menuHint = "You may type menu at any time.";
- string[] level1Passwords = { "books", "aisle", "shelf", "password", "font", "borrow" };
- string[] level2Passwords = { "prisoner", "handcuffs", "holster", "uniform", "arrest" };
- string[] level3Passwords = { "starfield", "telescope", "environment", "exploration", "astronauts" };
- // Game state
- int level;
- enum Screen { MainMenu, Password, Win };
- Screen currentScreen;
- string password;
- // Use this for initialization
- void Start ()
- {
- ShowMainMenu ();
- }
- void ShowMainMenu ()
- {
- currentScreen = Screen.MainMenu;
- Terminal.ClearScreen();
- Terminal.WriteLine("What would you like to hack into?");
- Terminal.WriteLine("Press 1 for the local library");
- Terminal.WriteLine("Press 2 for the police station");
- Terminal.WriteLine("Press 3 for NASA!");
- Terminal.WriteLine("Enter your selection:");
- }
- void OnUserInput(string input)
- {
- if (input == "menu") // we can always go direct to main menu
- {
- ShowMainMenu();
- }
- else if (currentScreen == Screen.MainMenu)
- {
- RunMainMenu(input);
- }
- else if (currentScreen == Screen.Password)
- {
- CheckPassword(input);
- }
- }
- void RunMainMenu(string input)
- {
- bool isValidLevelNumber = (input == "1" || input == "2" || input == "3");
- if (isValidLevelNumber)
- {
- level = int.Parse(input);
- AskForPassword();
- }
- else if (input == "007") // easter egg
- {
- Terminal.WriteLine("Please select a level Mr Bond!");
- }
- else
- {
- Terminal.WriteLine("Please choose a valid level");
- Terminal.WriteLine(menuHint);
- }
- }
- void AskForPassword()
- {
- currentScreen = Screen.Password;
- Terminal.WriteLine("We are connecting you to " + level);
- Terminal.WriteLine("Enter password. Hint: " + password.Anagram());
- PasswordGenerator();
- }
- void PasswordGenerator()
- {
- switch (level)
- {
- case 1:
- int index = Random.Range(0, level1Passwords.Length);
- password = level1Passwords[index];
- break;
- case 2:
- int index2 = Random.Range(0, level2Passwords.Length);
- password = level2Passwords[index2];
- break;
- case 3:
- int index3 = Random.Range(0, level3Passwords.Length);
- password = level3Passwords[index3];
- break;
- default:
- Debug.Log("Invalid Level boi"); //In case, if I will mess up with code too much
- break;
- }
- }
- void CheckPassword(string input)
- {
- if (input == password)
- {
- DisplayWinScreen();
- }
- else
- {
- AskForPassword();
- }
- }
- void DisplayWinScreen()
- {
- currentScreen = Screen.Win;
- Terminal.ClearScreen();
- ShowLevelReward();
- Terminal.WriteLine(menuHint);
- }
- void ShowLevelReward()
- {
- switch (level)
- {
- case 1:
- Terminal.WriteLine("Have a book...");
- Terminal.WriteLine(@"
- _______
- / //
- / //
- /_____ //
- (______(/
- "
- );
- break;
- case 2:
- Terminal.WriteLine("You got the prison key!");
- Terminal.WriteLine(@"
- __
- /0 \_______
- \__/-=' = '
- "
- );
- Terminal.WriteLine("Play again for a greater challenge.");
- break;
- case 3:
- Terminal.WriteLine(@"
- _ __ __ _ ___ __ _
- | '_ \ / _` / __|/ _` |
- | | | | (_| \__ \ (_| |
- |_| |_|\__,_|___)\__,_|
- "
- );
- Terminal.WriteLine("Welcome to NASA's internal system!");
- break;
- default:
- Debug.LogError("Invalid level reached");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement