I actually struggled with the concept of how to move from RunMainMenu() to StartGame() - which I renamed to RunGameMenu() (plus now I have RunWinMenu()) since input was already set to 1/2 … how to ask for the password first without declaring 1 or 2 as wrong.
I ended up passing some empty strings and doing exception.
This would be the code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hacker : MonoBehaviour {
// Game state
int level;
enum Screen { MainMenu, Password, Win };
string geslo;
Screen currentScreen;
// Use this for initialization
void Start() {
ShowMainMenu();
print("Hello " + "World");
}
void ShowMainMenu()
{
currentScreen = Screen.MainMenu;
Terminal.ClearScreen();
Terminal.WriteLine("You are closed in a kitchen escape room");
Terminal.WriteLine("To get out, you need to find right food");
Terminal.WriteLine("1 Easy: meat");
Terminal.WriteLine("2 Medium: Fruit");
Terminal.WriteLine("Type your food selection: ");
}
void OnUserInput(string input)
{
if (input == "menu")
{
ShowMainMenu();
}
else if (currentScreen == Screen.MainMenu)
{
RunMainMenu(input);
}
else if (currentScreen == Screen.Password)
{
RunGameMenu(input);
}
}
void RunMainMenu(string input)
{
if (input == "1")
{
level = 1;
geslo = "beef";
RunGameMenu("");
}
else if (input == "2")
{
level = 2;
geslo = "banana";
RunGameMenu("");
}
else
{
Terminal.WriteLine("You make no sense");
}
}
void RunGameMenu(string input)
{
currentScreen = Screen.Password;
Terminal.WriteLine("You have chosen level " + level);
if (input == geslo)
{
currentScreen = Screen.Win;
RunGameWin(geslo);
}
else if (input == "")
{
Terminal.WriteLine("Please type the password");
}
else
{
Terminal.WriteLine("Try again.");
}
}
void RunGameWin(string pravogeslo)
{
Terminal.WriteLine("Congratulations!!!");
Terminal.WriteLine("Password really was " + pravogeslo);
}
// Update is called once per frame
void Update () {
}
}