For some reason, when choosing 1, 2, or 3 for the level, I get that extra line that says “Please choose a valid level” even though I am choosing a valid level. I checked over my code and don’t see anything wrong with the code.
Here is my code:
// Game state
int level;
enum Screen { MainMenu, Password, Win };
Screen currentScreen;
string password;
// Use this for initialization
void Start()
{
ShowMainMenu();
}
void ShowMainMenu()
{
currentScreen = Screen.MainMenu;
Terminal.ClearScreen();
Terminal.WriteLine("Welcome to the Hacker Challenge Game");
Terminal.WriteLine("Choose 1 for Penny's Piggy Bank");
Terminal.WriteLine("Choose 2 for Sherlock Detective Agency");
Terminal.WriteLine("Choose 3 for Roswell Computer System");
Terminal.WriteLine("Enter your selection: ");
}
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);
}
}
void RunMainMenu(string input)
{
if (input == "1")
{
level = 1;
password = level1Passwords[2]; //todo make random later
StartGame();
}
else if (input == "2")
{
level = 2;
password = level2Passwords[3];
StartGame();
}
if (input == "3")
{
level = 3;
password = level3Passwords[2];
StartGame();
}
else if (input == "007")
{
Terminal.WriteLine("Please select a level Mr. Bond!");
}
else
{
Terminal.WriteLine("Please choose a valid level");
}
}
void StartGame()
{
currentScreen = Screen.Password;
Terminal.WriteLine("You have chosen level " + level);
Terminal.WriteLine("Please enter your password ");
}
void CheckPassword(string input)
{
if (input == password)
{
Terminal.WriteLine("Congratulations!");
}
else
{
Terminal.WriteLine("Incorrect. Try Again?");
}
}
}