This is my code, I try to go other way for fun and play around with some function. So it a bit messy.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hacker : MonoBehaviour
{
//Private Var
private string greeting = "Hello BMWalker";
private int levels; //Game Level
private enum Screen {MainMenu, Password, Win };
private Screen currentScreen;
//password var
private readonly string[] level1Pass = {"apple","dog","cat" };
private readonly string[] level2Pass = { "math", "ben", "todo" };
private readonly string[] level3Pass = { "salary", "student", "teacher" };
// Start is called before the first frame update
void Start()
{
TestingVar2(out greeting);
ShowMainMenu("Toyota");
}
// Function
void ShowMainMenu(string str) {
Terminal.ClearScreen();
Terminal.WriteLine(TestingVar(ref str));
Terminal.WriteLine("Hacking Terminal Successfully started !" +
"\n You are about to do hack other computer! Choose option below" +
"\n 1: Studen PC." +
"\n 2: Teacher PC." +
"\n 3: Principle PC." +
"\n Choose option above by: \b");
currentScreen = Screen.MainMenu;
levels = 0;
}
string TestingVar(ref string str) {
return str += " This is how it work";
}
void TestingVar2(out string str) {
str = "Greeting Ohlala here!";
}
void OnUserInput(string inputKeyword) {
if (inputKeyword == "menu")
{
ShowMainMenu(greeting);
}
else if (currentScreen == Screen.MainMenu)
{
ChooseGameOption(inputKeyword);
}
else if (currentScreen == Screen.Password) {
CheckInputPassword(inputKeyword);
}
}
void ChooseGameOption(string inputKeyword) {
switch (inputKeyword) {
case "1":
case "2":
case "3":
currentScreen = Screen.Password;
levels = int.Parse(inputKeyword);
Terminal.WriteLine("You choossing to hack option: "+ inputKeyword);
Terminal.WriteLine("Please Input password:");
break;
default:
Terminal.WriteLine("Please choose option above!");
break;
}
}
void WinGame() {
Terminal.ClearScreen();
Terminal.WriteLine("Congratdulation!");
}
void WrongPassMessage() {
Terminal.WriteLine("Invalid password!");
}
void CheckInputPassword(string inputPass) {
switch (levels) {
case 1:
if (ComparePassword(level1Pass, inputPass)) WinGame();
else WrongPassMessage();
break;
case 2:
if (ComparePassword(level2Pass, inputPass)) WinGame();
else WrongPassMessage();
break;
case 3:
if (ComparePassword(level3Pass, inputPass)) WinGame();
else WrongPassMessage();
break;
}
}
bool ComparePassword(string[] hackLevel ,string inputPass) {
foreach (string i in hackLevel) {
if (i == inputPass) {
return true;
}
}
return false;
}
}