Here is my echo back to StartGame() . I tested it out and was able to get the right response, now to see if there is a simpler way to write it out.
One thing that was repetitive was calling StartGame() in the if/else statements. One thing I did to simplify that was by doing the following. I don’t know if actually makes it simpler.
public class Hacker : MonoBehaviour
{
int level;
private void Awake()
{
Debug.Log("Awake");
}
// Start is called before the first frame update
void Start()
{
Debug.Log("Start");
ShowMainMenu();
}
void ShowMainMenu()
{
Terminal.ClearScreen();
Terminal.WriteLine("Welcome, Hacker.");
Terminal.WriteLine("Which system would you like to access?");
Terminal.WriteLine("");
Terminal.WriteLine("1 ) Library");
Terminal.WriteLine("2 ) Bank");
Terminal.WriteLine("3 ) Police Station");
Terminal.WriteLine("4 ) NASA");
Terminal.WriteLine("");
Terminal.WriteLine("Enter selection [1, 2, 3, or 4]: ");
}
void OnUserInput(string input)
{
if (input == "menu")
{
ShowMainMenu();
}
if (isInputValid(input))
{
StartGame();
}
}
private bool isInputValid(string input)
{
bool isValid = true;
if (input == "1")
{
level = 1;
}
else if (input == "2")
{
level = 2;
}
else if (input == "3")
{
level = 3;
}
else if (input == "4")
{
level = 4;
}
else
{
Terminal.WriteLine("Error: Pleasse choose 1, 2, 3, or 4");
isValid = false;
}
return isValid;
}
private void StartGame()
{
Terminal.WriteLine("You have chosen level: " + level);
}
}