I was able to complete the challenge but

I completed the challenge and even added a Win screen with state change by adding a terminal print command to a Winscreen function and then calling that function in another function called ShoWin, which was activated if the input == the password. Really happy with how I have been able to understand how to do this on my own. I know the extra functions could probably be wrapped into a single function, but I wanted to get practice calling functions.

The problem I faced,was that I tried to make the input.ToLower as all of my passwords were lowercase and so was the menu command. I know this makes it easier for the player/User, but iwanted to challenge myself by setting all input to lowercase. I also had problems with text formatting, like lines carrying over amd the text not reading correctly in the terminal. I will try to use a /n for new line.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hacker : MonoBehaviour
{
    // member variable Game State
    int level;

    enum Screen {MainMenu, Password, Win};

    string Password;


    Screen currentScreen;
    // Start is called before the first frame update
    void Start()
    {   
        
        ShowMainMenu();
        
    }

    void ShowMainMenu()
    {   
        currentScreen = Screen.MainMenu;
        Terminal.ClearScreen();
        Terminal.WriteLine("Hello Hacker");
        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 the NSA");
        Terminal.WriteLine("Press 4 for the GCHQ");
        Terminal.WriteLine("Enter your Selection.");
    }

    
    void OnUserInput(string input) 
    {
        if (input == "menu")   //we can always go directly to main menu 
        {
            ShowMainMenu();
            
        }

        else if (currentScreen == Screen.MainMenu)
        {
            RunMainMenu(input);
        }

        else if (currentScreen == Screen.Password)
        {
            input.ToLower();
            CheckPassword(input);
        }
    }

    void RunMainMenu(string input)
    {
        if (input == "1")
        {
            level = 1;
            Password = "book";
            StartGame();
        }

        else if (input == "2")
        {   
            level = 2;
            Password = "jail";
            StartGame();
        }

        else if (input == "3")
        {   
            level = 3;
            Password = "prism";
            StartGame();
        }

        else if (input == "4")
        {   
            level = 4;
            Password = "bond";
            StartGame();
        }

        else if (input == "007")
        {
            Terminal.WriteLine("The name's Bond, James Bond.");
        }

        else 
        {
            Terminal.WriteLine("Please choose a level or type 'menu' to return to the main menu");
        }
    }

    void StartGame()
    {
        currentScreen = Screen.Password;
        Terminal.WriteLine("You chose Level " + level);
        Terminal.WriteLine("Please Enter the correct Password.");

    }

    void CheckPassword(string input)
    {
        if (input == Password)
        {
            ShowWin();
        }
        else
        {
            Terminal.WriteLine("Wrong Password, please try again or type 'menu' to return to the main menu.");
            Terminal.WriteLine("What is the password?");
        }

    }

    void ShowWin()
    {
        currentScreen = Screen.Win;
        WinScreen();
    }
    void WinScreen()
    {
        Terminal.WriteLine("You have entered the correct password and won the game. Type 'menu to return to the main menu.");
    }
    
    

    
}

Privacy & Terms