Hi,
I come surprisingly very close to Ben’s code for the challenge but had an issue with one line of code that was working and now it is not.
I made sure that it was the same as Ben’s code but it still does not work.
Can anyone please help me understand what has gone wrong here?
Many thanks!
Error:
My 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 };
Screen currentScreen;
string password;
// Start is called before the first frame update
void Start()
{
ShowMainMenu();
}
void ShowMainMenu ()
{
currentScreen = Screen.MainMenu;
Terminal.ClearScreen();
Terminal.WriteLine("Hello");
Terminal.WriteLine("This computer is currently locked.");
Terminal.WriteLine("Press 1 for an Easy decrypt.");
Terminal.WriteLine("Press 2 for a Medium decrypt.");
Terminal.WriteLine("Press 3 for a Hard decrypt.");
Terminal.WriteLine("Enter your selection:");
}
void OnUserInput(string input)
{
if (input == "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 = "easy";
StartGame();
}
else if (input == "2")
{
level = 2;
password = "medium";
StartGame();
}
else if (input == "3")
{
level = 3;
password = "hard";
StartGame();
}
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: ");
}
// Update is called once per frame
void Update()
{
}
}
void CheckPassword(string input)
{
if (input == password)
{
Terminal.WriteLine("Well done! That is correct!");
}
else
{
Terminal.WriteLine("Sorry, thats is incorrect! Please try again.");
}
}
}