Guest User

Hacker.cs

a guest
Jul 18th, 2019
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.01 KB | None | 0 0
  1. //using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Hacker : MonoBehaviour
  7. {
  8.     string[] level1Passwords = { "book", "books", "student", "students", "learning", "teacher", "teachers",  "degree", "degrees", "learn", "class", "classes" };
  9.     string[] level2Passwords = { "money", "banker", "bankers", "power", "suit", "suits", "paper", "debt", "loan", "safe", "cash", "evil", "credit" };
  10.     string[] level3Passwords = { "conspiracy", "secret", "secrets", "service", "services", "surveillance", "mission", "missions", "crime", "villain", "alien", "aliens" };
  11.  
  12.     string[] level1Gamewords = { "knowledge", "master", "professor" };
  13.     string[] level2Gamewords = { "society", "credit card", "commercial" };
  14.     string[] level3Gamewords = { "extraterrestial", "secret service", "conspiracy theory" };
  15.  
  16.     int level;
  17.     float currentCountdownVal;
  18.  
  19.     int tryCounter = 0;
  20.     string password;
  21.  
  22.     string gameword1;
  23.     string gameword2;
  24.     string gameword3;
  25.    
  26.     enum Screen { MainMenu, Password, Level, Win, GameOver }
  27.  
  28.     Screen currentScreen;
  29.  
  30.     void Start()
  31.     {
  32.         ShowMainMenu();
  33.     }
  34.  
  35.     void ShowMainMenu()
  36.     {
  37.         currentScreen = Screen.MainMenu;
  38.         Terminal.WriteLine("What would you like to hack?\n");
  39.         StartCoroutine(MainMenuExecution(1.0f));
  40.     }
  41.  
  42.     void Update()
  43.     {
  44.        
  45.     }
  46.    
  47.     IEnumerator MainMenuExecution(float time)
  48.     {
  49.         yield return new WaitForSeconds(time);
  50.         Terminal.WriteLine("Enter 'university',\nto hack into the local university\n");
  51.         yield return new WaitForSeconds(time);
  52.         Terminal.WriteLine("Enter 'national bank',\nto hack into the national bank\n");
  53.         yield return new WaitForSeconds(time);
  54.         Terminal.WriteLine("Enter 'Federal Bureau of Intelligence',\nto hack into the FBI\n");
  55.         yield return new WaitForSeconds(time);
  56.         Terminal.WriteLine("Enter your selection:");
  57.     }
  58.  
  59.     void OnUserInput(string input)
  60.     {
  61.         if (input == "menu")
  62.         {
  63.             Terminal.ClearScreen();
  64.             ShowMainMenu();
  65.         }
  66.         else if (currentScreen == Screen.MainMenu)
  67.         {
  68.             RunMainMenu(input);
  69.         }
  70.         else if (currentScreen == Screen.Password)
  71.         {
  72.             CheckPassword(input);
  73.         }
  74.         else if (currentScreen == Screen.Level)
  75.         {
  76.             LevelInput(input);
  77.         }
  78.         else if (currentScreen == Screen.GameOver)
  79.         {
  80.             RestartOrExit(input);
  81.         }
  82.     }
  83.  
  84.  
  85.     void RunMainMenu(string input)
  86.     {
  87.         switch (input)
  88.         {
  89.             case "university":
  90.                 level = 1;
  91.                 SelectingPassword();
  92.                 break;
  93.             case "national bank":
  94.                 level = 2;
  95.                 SelectingPassword();
  96.                 break;
  97.             case "Federal Bureau of Intelligence":
  98.             case "federal bureau of intelligence":
  99.                 level = 3;
  100.                 SelectingPassword();
  101.                 break;
  102.             case "your selection":
  103.                 Terminal.WriteLine("\nHA. You're really funny.");
  104.                 break;
  105.             default:
  106.                 Terminal.WriteLine("\nNot a valid input. Please try again:");
  107.                 break;
  108.         }
  109.     }
  110.  
  111.     void SelectingPassword()
  112.     {
  113.         currentScreen = Screen.Password;
  114.  
  115.         Terminal.ClearScreen();
  116.  
  117.         switch (level)
  118.         {
  119.             case 1:
  120.                 SetRandomPassword();
  121.                 Terminal.WriteLine("You chose the university. This will be easy.\n");
  122.                 Terminal.WriteLine("*Selecting random password*\n(Hint: Words that fit to university.)");
  123.                 Terminal.WriteLine("Please enter the password: ");
  124.                 break;
  125.             case 2:
  126.                 SetRandomPassword();
  127.                 Terminal.WriteLine("This bank is pretty secure. Good Luck.\n");
  128.                 Terminal.WriteLine("*Selecting random password*\n(Hint: Words that fit to national bank.)");
  129.                 Terminal.WriteLine("Please enter the password: ");
  130.                 break;
  131.             case 3:
  132.                 SetRandomPassword();
  133.                 Terminal.WriteLine("The FBI is unhackable. Or is it?\n");
  134.                 Terminal.WriteLine("*Selecting random password*\n(Hint: Words that fit to the FBI.)");
  135.                 Terminal.WriteLine("Please enter the password: ");
  136.                 break;
  137.             default:
  138.                 Terminal.WriteLine("No level selected. How did this happen?");
  139.                 Terminal.WriteLine("Restarting game...");
  140.                 ShowMainMenu();
  141.                 break;
  142.         }
  143.     }
  144.  
  145.     void SetRandomPassword()
  146.     {
  147.         switch (level)
  148.         {
  149.             case 1:
  150.                 password = level1Passwords[Random.Range(0, level1Passwords.Length)];
  151.                 break;
  152.             case 2:
  153.                 password = level2Passwords[Random.Range(0, level2Passwords.Length)];
  154.                 break;
  155.             case 3:
  156.                 password = level3Passwords[Random.Range(0, level3Passwords.Length)];
  157.                 break;
  158.             default:
  159.                 Terminal.WriteLine("No level selected. How did this happen?");
  160.                 Terminal.WriteLine("Restarting game...");
  161.                 ShowMainMenu();
  162.                 break;
  163.         }
  164.     }
  165.  
  166.     void CheckPassword(string input)
  167.     {
  168.         if (input == password)
  169.         {
  170.             Terminal.WriteLine("Starting level..");
  171.  
  172.             switch (level)
  173.             {
  174.                 case 1:
  175.                     StartCoroutine(StartLevelExecution(120));
  176.                     break;
  177.                 case 2:
  178.                     StartCoroutine(StartLevelExecution(90));
  179.                     break;
  180.                 case 3:
  181.                     StartCoroutine(StartLevelExecution(60));
  182.                     break;
  183.                 default:
  184.                     Terminal.WriteLine("No level selected. How did this happen?");
  185.                     Terminal.WriteLine("Restarting game...");
  186.                     ShowMainMenu();
  187.                     break;
  188.             }
  189.         }
  190.         else
  191.         {
  192.             Terminal.WriteLine("Sorry wrong password. Try again:");
  193.             tryCounter++;
  194.  
  195.             if (tryCounter == 5)
  196.             {
  197.                 Terminal.WriteLine("You already took " + tryCounter + " tries.");
  198.             }
  199.             else if (tryCounter >= 5 && tryCounter <= 10)
  200.             {
  201.                 switch (level)
  202.                 {
  203.                     case 1:
  204.                         Terminal.WriteLine("Hint: Words that fit to university");
  205.                         break;
  206.                     case 2:
  207.                         Terminal.WriteLine("Hint: Words that fit to national bank");
  208.                         break;
  209.                     case 3:
  210.                         Terminal.WriteLine("Hint: Words that fit to the FBI");
  211.                         break;
  212.                     default:
  213.                         Terminal.WriteLine("No level selected. How did this happen?");
  214.                         Terminal.WriteLine("Restarting game...");
  215.                         ShowMainMenu();
  216.                         break;
  217.                 }
  218.                 if (tryCounter == 10)
  219.                 {
  220.                     ShowPasswordHelp();
  221.                 }
  222.             }
  223.         }
  224.     }
  225.  
  226.     void ShowPasswordHelp()
  227.     {
  228.         Terminal.ClearScreen();
  229.         Terminal.WriteLine("You already took 10 tries.");
  230.         Terminal.WriteLine("Here is some help for you.");
  231.  
  232.         switch (level)
  233.         {
  234.             case 1:
  235.                 Terminal.WriteLine("Words that fit:");
  236.                 foreach(string password in level1Passwords)
  237.                 {
  238.                     Terminal.WriteLine(password.ToString());
  239.                 }
  240.                 break;
  241.             case 2:
  242.                 Terminal.WriteLine("Words that fit:");
  243.                 foreach (string password in level2Passwords)
  244.                 {
  245.                     Terminal.WriteLine(password.ToString());
  246.                 }
  247.                 break;
  248.             case 3:
  249.                 Terminal.WriteLine("Words that fit:");
  250.                 foreach (string password in level3Passwords)
  251.                 {
  252.                     Terminal.WriteLine(password.ToString());
  253.                 }
  254.                 break;
  255.             default:
  256.                 Terminal.WriteLine("No level selected. How did this happen?");
  257.                 Terminal.WriteLine("Restarting game...");
  258.                 ShowMainMenu();
  259.                 break;
  260.         }
  261.  
  262.         StartCoroutine(PasswordHelpDone(1.5f));
  263.     }
  264.  
  265.     IEnumerator PasswordHelpDone(float time)
  266.     {
  267.         yield return new WaitForSeconds(time);
  268.         Terminal.WriteLine("\nThis screen won't be shown again. Memorize these words.");
  269.         yield return new WaitForSeconds(10.0f);
  270.         Terminal.ClearScreen();
  271.         yield return new WaitForSeconds(time);
  272.         Terminal.WriteLine("Now enter the password: ");
  273.     }
  274.  
  275.     void SetGameWords()
  276.     {
  277.         switch (level)
  278.         {
  279.             case 1:
  280.                 gameword1 = level1Gamewords[0];
  281.                 gameword2 = level1Gamewords[1];
  282.                 gameword3 = level1Gamewords[2];
  283.                 break;
  284.             case 2:
  285.                 gameword1 = level2Gamewords[0];
  286.                 gameword2 = level2Gamewords[1];
  287.                 gameword3 = level2Gamewords[2];
  288.                 break;
  289.             case 3:
  290.                 gameword1 = level3Gamewords[0];
  291.                 gameword2 = level3Gamewords[1];
  292.                 gameword3 = level3Gamewords[2];
  293.                 break;
  294.         }
  295.     }
  296.  
  297.     public IEnumerator StartLevelExecution(float countdownVal)
  298.     {
  299.         currentCountdownVal = countdownVal;
  300.  
  301.         currentScreen = Screen.Level;
  302.  
  303.         yield return new WaitForSeconds(1.5f);
  304.         Terminal.ClearScreen();
  305.         yield return new WaitForSeconds(1.5f);
  306.         Terminal.WriteLine("You have " + countdownVal + " seconds to guess the words.\nYou have unlimited attempts.");
  307.         yield return new WaitForSeconds(1.0f);
  308.         Terminal.WriteLine("GO!");
  309.  
  310.         StartLevel();
  311.  
  312.         while (currentCountdownVal > 0)
  313.         {
  314.             yield return new WaitForSeconds(1.0f);
  315.             currentCountdownVal--;
  316.         }
  317.  
  318.         if (currentCountdownVal == 30)
  319.         {
  320.             Terminal.WriteLine("You have 30 seconds left.");
  321.         }
  322.         else if (currentCountdownVal == 10)
  323.         {
  324.             Terminal.WriteLine("You have 10 seconds left. Hurry up!");
  325.         }
  326.         else if (currentCountdownVal == 0)
  327.         {
  328.             GameOver();
  329.         }
  330.     }
  331.  
  332.     void StartLevel()
  333.     {
  334.         SetGameWords();
  335.  
  336.         Terminal.WriteLine("Word 1: " + gameword1.Anagram());
  337.     }
  338.  
  339.     private void LevelInput(string input)
  340.     {
  341.         if (input == gameword1)
  342.         {
  343.             Terminal.WriteLine("Word 2: " + gameword2.Anagram());
  344.         }
  345.         else if (input == gameword2)
  346.         {
  347.             Terminal.WriteLine("Word 3: " + gameword3.Anagram());
  348.         }
  349.         else if (input == gameword3)
  350.         {
  351.             DisplayWinScreen();
  352.         }
  353.         else
  354.         {
  355.             Terminal.WriteLine("Wrong word! Try again:");
  356.         }
  357.     }
  358.  
  359.     void DisplayWinScreen()
  360.     {
  361.         currentScreen = Screen.Win;
  362.         Terminal.ClearScreen();
  363.         ShowLevelReward();
  364.     }
  365.  
  366.     void ShowLevelReward()
  367.     {
  368.         Terminal.WriteLine("Well done!");
  369.  
  370.         switch (level)
  371.         {
  372.             case 1:
  373.                 Terminal.WriteLine("Have a book:");
  374.                 Terminal.WriteLine(@"
  375.      __...--~~~~~-._   _.-~~~~~--...__
  376.    //               `V'               \\
  377.   //                 |                 \\
  378.  //__...--~~~~~~-._  |  _.-~~~~~~--...__\\
  379. //__.....----~~~~._\ | /_.~~~~----.....__\\
  380. ====================\\|//====================
  381.                    `---`
  382.                                   ");
  383.                 break;
  384.             case 2:
  385.                 Terminal.WriteLine("Have a dollar:");
  386.                 Terminal.WriteLine(@"
  387. ___________________________________
  388. |#######====================#######|
  389. |#(1)*UNITED STATES OF AMERICA*(1)#|
  390. |#**          /===\   ********  **#|
  391. |*# {G}      | (~) |             #*|
  392. |#*  ******  | /v\ |    O N E    *#|
  393. |#(1)         \===/            (1)#|
  394. |##=========ONE DOLLAR===========##|
  395. ------------------------------------
  396.                                   ");
  397.                 break;
  398.             case 3:
  399.                 Terminal.WriteLine("Have an FBI badge:");
  400.                 Terminal.WriteLine(@"
  401. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  402. ⠀⠀⠀⠀⠀⠀⠀⣀⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣀⠀⠀⠀⠀⠀⠀⠀
  403. ⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀
  404. ⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀
  405. ⠀⠀⢠⣿⡿⠿⠿⠿⠿⠿⠿⠿⣿⠿⠿⠿⠿⠿⠿⢿⣿⣿⣿⠿⠿⢿⣿⡄⠀⠀
  406. ⠀⢀⣿⣿⡇⠀⠀⣠⣤⣄⣀⣠⣿⠀⠀⢀⣤⣀⡀⠀⠘⣿⣿⠀⠀⢸⣿⣿⡀⠀
  407. ⠀⢸⣿⣿⡇⠀⠀⣿⣿⣿⣿⣿⣿⠀⠀⢸⣿⣿⠟⠀⠀⣿⣿⠀⠀⢸⣿⣿⡇⠀
  408. ⠀⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠺⣿⣿⠀⠀⢸⣿⣿⡧⠀
  409. ⠀⢸⣿⣿⡇⠀⠀⣿⣿⣿⣿⣿⣿⠀⠀⢸⣿⣿⣿⠀⠀⢹⣿⠀⠀⢸⣿⣿⡇⠀
  410. ⠀⠈⣿⣿⡇⠀⠀⣿⣿⣿⣿⣿⣿⠀⠀⠈⠛⠛⠉⠀⢀⣾⣿⠀⠀⢸⣿⣿⠃⠀
  411. ⠀⠀⠸⣿⣷⣶⣶⣿⣿⣿⣿⣿⣿⣶⣶⣶⣶⣶⣶⣾⣿⣿⣿⣶⣶⣾⣿⠇⠀⠀
  412. ⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠀⠀⠀
  413. ⠀⠀⠀⠀⠀⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⠀⠀⠀⠀
  414. ⠀⠀⠀⠀⠀⠀⠀⠙⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠋⠀⠀⠀⠀⠀⠀⠀
  415. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠙⠛⠛⠋⠉⠉⠀⠀⠀⠀⠀⠀
  416.  
  417.                                   ");
  418.                 break;
  419.             default:
  420.                 Terminal.WriteLine("No level selected. How did this happen?");
  421.                 Terminal.WriteLine("Restarting game...");
  422.                 ShowMainMenu();
  423.                 break;
  424.         }
  425.     }
  426.     void GameOver()
  427.     {
  428.         currentScreen = Screen.GameOver;
  429.         Terminal.ClearScreen();
  430.         Terminal.WriteLine("GAME OVER!\nYou didn't make it in time.\nThe police is on their way.\n");
  431.         Terminal.WriteLine("Press [ENTER] to continue..");
  432.     }
  433.  
  434.     void RestartOrExit(string input)
  435.     {
  436.         Terminal.WriteLine("If you want to restart the game, type 'restart' or 'menu'.");
  437.         Terminal.WriteLine("If you want to exit the game, type 'exit' or 'quit'.");
  438.  
  439.         if (input == "restart" || input == "menu")
  440.         {
  441.             Terminal.ClearScreen();
  442.             ShowMainMenu();
  443.         }
  444.         else if (input == "exit" || input == "quit")
  445.         {
  446.             Application.Quit();
  447.         }
  448.     }
  449. }
Add Comment
Please, Sign In to add comment