Hey guys!
So I’m attempting to run this code but I seem to be getting a stack overflow. Not sure what that means or where the issue is.
Thanks!
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hacker : MonoBehaviour
{
// Game State
int level;
enum Screen { MainMenu, Password, Win };
Screen currentScreen;
// Start is called before the first frame update
void Start()
{
ShowMainMenu ();
}
void ShowMainMenu()
{
currentScreen = Screen.MainMenu;
Terminal.ClearScreen();
Terminal.WriteLine("Sup yo");
Terminal.WriteLine("You need to hack into these servers");
Terminal.WriteLine("Press 1 to access the School");
Terminal.WriteLine("Press 2 to access the Museum");
Terminal.WriteLine("Press 3 to acces the Government");
}
void OnUserInput(string input)
{
if (input == "menu") // we can always go direct to main menu
{
level = 0;
ShowMainMenu();
}
else if (currentScreen == Screen.MainMenu) // This runs the main menu
{
RunMainMenu(input);
}
}
void RunMainMenu(string input) // Main menu is controlled here
{
if (input == "1")
{
level = 1;
StartGame(input);
}
else if (input == "2")
{
level = 2;
StartGame(input);
}
else if (input == "3")
{
level = 3;
StartGame(input);
}
else if (input == "117")
{
Terminal.WriteLine("Wake me when you need me.");
}
else
{
Terminal.WriteLine("Please choose a valid option.");
}
}
void StartGame(string input)
{
currentScreen = Screen.Password;
Terminal.WriteLine("You have chosen level " + level);
Terminal.WriteLine("Please enter password: ");
if (level == 1)
{
RunEasy(input);
}
if (level == 2)
{
RunMedium(input);
}
if (level == 3)
{
RunHard(input);
}
}
void RunEasy(string input)
{
Terminal.WriteLine("alscs");
if (input == "class")
{
Terminal.WriteLine("Password Successful.");
ShowMainMenu();
}
else
{
Terminal.WriteLine("Fail. Please Try Again:");
RunEasy(input);
}
}
void RunMedium(string input)
{
Terminal.WriteLine("itgnpain");
if (input == "painting")
{
Terminal.WriteLine("Password Successful");
ShowMainMenu();
}
else
{
Terminal.WriteLine("Fail. Please Try Again:");
RunMedium(input);
}
}
void RunHard(string input)
{
Terminal.WriteLine("isetalnrpsed");
if (input == "presidential")
{
Terminal.WriteLine("Password Successful");
ShowMainMenu();
}
else
{
Terminal.WriteLine("Fail. Please Try Again:");
RunHard(input);
}
}
// Update is called once per frame
void Update()
{
}
}