Hey guys,
This is my first work of C# script,
beside following the lectures, I attempts to add two concepts:
- An additional screen at beginning that could type a name you like.
- A field of “try Easter Egg” in Unity Debug, since I set several eggs, it will swap randomly if you enter a invalid level.
It still need to be simplified, please feel free to let me know your feedback,
and ENJOY!
using UnityEngine;
public class Hacker : MonoBehaviour
{
// Game configuration data
const string restartGame = "You can type menu to restart.";
string[] level1Passwords = { "books", "students", "teacher", "blackboard" };
string[] level2Passwords = { "bread", "apple", "beef", "pork", "candy" };
string[] level3Passwords = { "gift", "shopping", "purchase", "MUJI" };
string[] level4Passwords = { "wife", "mimi", "handpan", "grandmom", "parents" };
string[] easterEgg = { "I don't know", "I'm scared", "see you" };
// Game state
int level;
enum Screen { UserName, MainMenu, Password, Win };
Screen currentScreen;
string Password;
string tryEasterEgg;
string userName;
// Use this for initialization
void Start()
{
ShowNamingScreen();
}
void ShowNamingScreen()
{
currentScreen = Screen.UserName;
Terminal.WriteLine("Good day agent!");
Terminal.WriteLine("Please enter your ID:");
}
void ShowMainMenu(string greeting)
{
currentScreen = Screen.MainMenu;
Terminal.ClearScreen();
Terminal.WriteLine(greeting);
Terminal.WriteLine("Select the target you want to invade:");
Terminal.WriteLine("1) School");
Terminal.WriteLine("2) Grocery");
Terminal.WriteLine("3) Department Store");
Terminal.WriteLine("4) Your Home");
Terminal.WriteLine("Where do you want to invite?");
tryEasterEgg = easterEgg[Random.Range(0, easterEgg.Length)];
}
void OnUserInput(string input)
{
if (input == "menu")
{
ShowMainMenu("Nice to see you again, " + userName + "!");
}
else if (currentScreen == Screen.UserName)
{
RunUserName(input);
}
else if (currentScreen == Screen.MainMenu)
{
RunMainMenu(input);
}
else if (currentScreen == Screen.Password)
{
CheckPassword(input);
}
}
void RunUserName(string input)
{
userName = input;
ShowMainMenu("Hey " + userName + "!");
}
void RunMainMenu(string input)
{
tryEasterEgg = easterEgg[Random.Range(0, easterEgg.Length)];
bool isValidLevelNumber = (input == "1" || input == "2" || input == "3" || input == "4");
if (isValidLevelNumber)
{
level = int.Parse(input);
GuessingPassword();
}
else if (input == "I'm scared")
{
Terminal.WriteLine("");
Terminal.WriteLine("your mommy isn't here~");
Terminal.WriteLine(restartGame);
}
else if (input == "I don't know")
{
Terminal.WriteLine("");
Terminal.WriteLine("You ought to own your life!");
Terminal.WriteLine(restartGame);
}
else if (input == "see you")
{
Terminal.WriteLine("");
Terminal.WriteLine("later!");
Terminal.WriteLine(restartGame);
}
else
{
Terminal.WriteLine("Please choose a valid level.");
}
}
void GuessingPassword()
{
currentScreen = Screen.Password;
Terminal.ClearScreen();
SetRamdomPassword();
Terminal.WriteLine("Please enter your password:");
Terminal.WriteLine("hint << " + Password.Anagram() + " >>");
Terminal.WriteLine("");
Terminal.WriteLine(restartGame);
}
void SetRamdomPassword()
{
switch (level)
{
case 1:
Password = level1Passwords[Random.Range(0, level1Passwords.Length)];
break;
case 2:
Password = level2Passwords[Random.Range(0, level2Passwords.Length)];
break;
case 3:
Password = level3Passwords[Random.Range(0, level3Passwords.Length)];
break;
case 4:
Password = level4Passwords[Random.Range(0, level4Passwords.Length)];
break;
}
}
void CheckPassword(string input)
{
if (input == Password)
{
WinScreen();
}
else
{
GuessingPassword();
}
}
void WinScreen()
{
currentScreen = Screen.Win;
Terminal.ClearScreen();
ShowLevelReward();
Terminal.WriteLine(restartGame);
}
void ShowLevelReward()
{
switch (level)
{
case 1:
Level1Win();
break;
case 2:
Level2Win();
break;
case 3:
Level3Win();
break;
case 4:
Level4Win();
break;
}
}
void Level1Win()
{
Terminal.WriteLine("STUDY TIME! ^___^");
Terminal.WriteLine(@"
_______
/ //
/ ^ ^ //
/______//
(______(/
");
}
void Level2Win()
{
Terminal.WriteLine("DINNER TIME! ^___<");
Terminal.WriteLine(@"
__
| | | / |
|_|_| | |
| | |
| |_|
| |
| |
");
}
void Level3Win()
{
Terminal.WriteLine("SHOPPING TIME! >___^");
Terminal.WriteLine(@"
____
__/____\__
| |
| ^ ^ |
|__________|
");
}
void Level4Win()
{
Terminal.WriteLine("WELLCOME HOME! z___z");
Terminal.WriteLine(@"
__
_||___
/------\
/--------\
/__________\
| ___ |
|____|_|_|
");
}
// Update is called once per frame
void Update()
{
}
}