Kind of succeeded

I accomplished the basic task but the biggest error was that if the player guessed the correct password for a different level, they would still enter the Win screen. I didn’t know how to handle the ‘level’ variable either. However my code was able to check the user’s guess, compare it to a variable, and change to a different enum accordingly.

public class Hacker : MonoBehaviour
{
    // Game State
    int level;
    enum Screen { MainMenu, Password, Win };
    Screen currentScreen;
    string password; // var to store guesses

    // Start is called before the first frame update
    void Start()
    {
        ShowMainMenu();
    }
    void ShowMainMenu() // displays the menu screen at start and if user types 'menu'
    {
        currentScreen = Screen.MainMenu;
        Terminal.ClearScreen();
        Terminal.WriteLine("Please select a terminal to hack.");
        Terminal.WriteLine("Press 1 for Your Granny's Sony Vaio ");
        Terminal.WriteLine("Press 2 for College Records");
        Terminal.WriteLine("Enter your selection: ");
    }
    void OnUserInput(string input) // accepts input from user
    {
        if (input == "menu") // to go directly to main menu
        {
            ShowMainMenu();
        }
        else if (currentScreen == Screen.MainMenu)
        {
            RunMainMenu(input);
        }
        else if (currentScreen == Screen.Password)
        {
            PasswordGuess(input);
        }
        else if (currentScreen == Screen.Win)
        {
            ShowMainMenu();
        }
        
    }
    void RunMainMenu(string input) // checks user input at menu screen
    {
       
        if (input == "1")
        {
            level = 1;
            StartGame();
        }
        else if (input == "2")
        {
            level = 2;
            StartGame();
        }
               else if (input == "lamb")
        {
            Terminal.WriteLine("Hello Clarice.");
        }
        else
        {
            Terminal.WriteLine("Please enter a valid argument.");
        }
    }
    void StartGame() //displays after user selects level
    {
        currentScreen = Screen.Password;
        Terminal.WriteLine("You have chosen level " + level);
        Terminal.WriteLine("Please enter the password.");
    }
    void PasswordGuess(string input) // two difficulties for now
    {
        if (input == "cookie")
        {
            password = "cookie";
            WinScreen();
        }
        else if (input == "alcohol")
        {
            password = "alcohol";
            WinScreen();
        }
        else
        {
            Terminal.WriteLine("Incorrect Password. Please try again");
        }
    }
    void WinScreen()
    {
        currentScreen = Screen.Win;
        Terminal.ClearScreen();
        
        if (level == 1)
        {
            Terminal.WriteLine("Password Accepted.");
            Terminal.WriteLine("Hi granny, enjoy your cat picture collection.");
        }
        else if (level == 2)
        {
            Terminal.WriteLine("Password Accepted.");
            Terminal.WriteLine("Welcome to University of Love's Student Record Database.");
        }
        
    }
}

It’s probably little hard to read. My biggest problem was that I didn’t use the password variable efficiently. I saved this code before watching the rest of the lesson.

1 Like

Amazing job with your code!

Privacy & Terms