It took me forever to figure out that I had to actually continue using OnUserInput to get inputs to work. Then it took me awhile to figure out that I needed to change my screen to get it to stop looping after I got the password correct but I finally got it!
public class Hacker : MonoBehaviour {
// Game state
int level;
enum Screen { MainMenu, Password, Win, Reset};
Screen currentScreen;
// Passwords
string easy1 = "duck";
string easy2 = "goose";
string med1 = "chocolate";
string med2 = "strawberry";
string hard1 = "kangaroo";
string hard2 = "elephant";
// Use this for initialization
void Start () {
ShowMainMenu();
}
void ShowMainMenu()
{
currentScreen = Screen.MainMenu;
Terminal.ClearScreen();
Terminal.WriteLine("RED ALERT!!");
Terminal.WriteLine("THE NYX VIRUS HAS BEEN DISPERSED!");
Terminal.WriteLine("Crack the code, save the world!");
Terminal.WriteLine("Only a special person can do this...");
Terminal.WriteLine("What kind of person are you? \n");
Terminal.WriteLine("1 - Scavenger");
Terminal.WriteLine("2 - Nomad");
Terminal.WriteLine("3 - Survivor \n");
Terminal.WriteLine("You are a: ");
}
// this should only decide who to handle input, not actually do it
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);
}
else if (currentScreen == Screen.Reset)
{
CheckPassword(input);
}
}
void RunMainMenu(string input)
{
if (input == "1")
{
level = 1;
StartMenu();
}
else if (input == "2")
{
level = 2;
StartMenu();
}
else if (input == "3")
{
level = 3;
StartMenu();
}
else if (input == "007")
{
Terminal.WriteLine("Welcome back, Mr. Bond. Which level would you like?");
}
else
{
Terminal.WriteLine("Please choose a valid level.");
}
}
void StartMenu()
{
currentScreen = Screen.Password;
Terminal.WriteLine("You have chosen level " + level);
Terminal.WriteLine("Please insert your password: ");
}
// the user will insert their password guesses
void CheckPassword(string input)
{
currentScreen = Screen.Win; //placing this here so that the screen won't reset to the password screen when winning
if (level == 1 && (input == easy1 || input == easy2)) // level 1 password check
{
Terminal.WriteLine("Good guessing, Scavenger!");
EndGame();
}
else if (level == 2 && (input == med1 || input == med2)) // level 2 password check
{
Terminal.WriteLine("Great job, Nomad!");
EndGame();
}
else if (level == 3 && (input == hard1 || input == hard2)) // level 3 password check
{
Terminal.WriteLine("Never doubted you, Survivor!");
EndGame();
}
else
{
PasswordReset();
}
}
// if the password is wrong, the menu will go back to the beginning
// of the password screen
void PasswordReset()
{
currentScreen = Screen.Reset;
Terminal.WriteLine("Sorry, your password is no good.\n");
Terminal.WriteLine("Please try another password: ");
}
// just a placeholder to end the game for now
void EndGame()
{
Terminal.WriteLine("Good job so far!\nPrepare for the next challenge!\n");
Terminal.WriteLine("Goodbye for now!");
return;
}
}