I designed the win screens (level 1 is the police station and 2 is NASA)
I also added a fail mechanic,
which is not yet implemented as a fourth game state but could easily be.
edit: in the first reply, after cleanup, it is.
using UnityEngine;
public class Hacker : MonoBehaviour
{
//Game configuration data
//string[ ] level0Passwords = { "book", "author", "shelf", "borrow", "research" };
string[ ] level1Passwords = { "intervention", "harassment", "security", "profiler" };
string[ ] level2Passwords = { "armstrong", "pleiades", "andromeda", "endeavour", "supermassive", "interplanetary" };
//Game state
string chosenName = "stranger";
string password;
int level;
int attempts;
enum Screen { MainMenu, Password, Win }
Screen currentScreen = Screen.MainMenu;
// Start is called before the first frame update
void Start()
{
ShowMainMenu("stranger");
}
private void Update()
{
//print("0 level: " + level0Passwords[Random.Range(0, level1Passwords.Length)]);
//print("1st level: " + level1Passwords[Random.Range(0, level2Passwords.Length)]);
//print("2nd level: " + level2Passwords[Random.Range(0, level3Passwords.Length)]);
}
void ShowMainMenu(string username)
{
Terminal.ClearScreen();
Terminal.WriteLine("Hello, " + username);
Terminal.WriteLine("You've made it this far");
Terminal.WriteLine("Choose your battles wisely");
Terminal.WriteLine("");
Terminal.WriteLine("Enter 1 for police station archives;");
Terminal.WriteLine("Enter 2 for NASA admin;");
Terminal.WriteLine("");
}
void RunMainMenu(string input)
{
bool isValidLevelNumber = (input == "1" || input == "2");
if (isValidLevelNumber)
{
level = int.Parse(input);
StartGame();
}
else if (input == "my name is Bogdan") //easter egg
{
chosenName = "Bogdan";
ShowMainMenu(chosenName);
}
else
{
Terminal.WriteLine("input unrecognized");
}
}
private void StartGame()
{
currentScreen = Screen.Password;
Terminal.ClearScreen();
switch (level)
{
case 1:
password = level1Passwords[Random.Range(0, level1Passwords.Length)];
attempts = 5;
break;
case 2:
password = level2Passwords[Random.Range(0, level2Passwords.Length)];
attempts = 3;
break;
default:
Debug.LogError("Invalid level number");
break;
}
Terminal.WriteLine("Please enter your password");
}
void CheckPassword(string input)
{
if (input == password)
{
DisplayWinScreen();
}
else if (attempts > 0)
{
attempts--;
if (attempts > 1)
{
Terminal.WriteLine("Wrong. Please mind your own business.");
}
else if (attempts == 1)
{
Terminal.WriteLine("This is your last warning.");
}
else
{
Terminal.ClearScreen();
if (level == 1)
{
Terminal.WriteLine("Resisting arrest will have worse consequences.");
}
else
{
Terminal.WriteLine("The authorities have been informed.");
}
}
}
}
void DisplayWinScreen()
{
if (attempts > 0)
{
Terminal.ClearScreen();
currentScreen = Screen.Win;
ShowLevelReward();
}
}
void ShowLevelReward()
{
switch(level)
{
case 1:
Terminal.WriteLine("Welcome back, officer!");
Terminal.WriteLine(@"
, /\ ,
/ '-' '-' \
| POLICE |
\ .--. /
| ( 19 ) |
\ '--' /
'--. .--'
jgs \/
");
break;
case 2:
Terminal.WriteLine(@"
,,)))))));,
__))))))))))))));,
-\(((((''''(((((((( >~
--==//////(('' . `)))))),
))| @ ;-. (((((
( `| / ) )))
| | | (
o_); ;
;
");
Terminal.WriteLine("It is safe to answer your phone.");
break;
default:
Debug.LogError("Invalid level number");
break;
}
}
void OnUserInput(string input)
{
if (input == "menu")
{
currentScreen = Screen.MainMenu;
ShowMainMenu(chosenName);
}
else if (currentScreen == Screen.MainMenu)
{
RunMainMenu(input);
}
else if (currentScreen == Screen.Password)
{
CheckPassword(input);
}
}
}
>