So I struggled with this (it took me 2 hours!), but I feel like I learnt a lot and gained a lot of confidence.
Also was wondering how to embed my code into the post like other people have done?
Very messy, but here’s my first Solo Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hacker : MonoBehaviour
{
//game state(s)
int gameLevel;
enum Screen {MainMenu, Password, Win};
Screen currentScreen = Screen.MainMenu;
void Start()
{
ShowMainMenu(“Hello User.”);
}
void ShowMainMenu(string greeting)
{
Terminal.ClearScreen();
Terminal.WriteLine(greeting);
Terminal.WriteLine(“What would you like to break into?”);
Terminal.WriteLine(“Press the corresponding number key “);
Terminal.WriteLine(“and press Enter to choose:”);
Terminal.WriteLine(””);
Terminal.WriteLine(“1. Your Gran’s Desktop.”);
Terminal.WriteLine(“2. The Pentagon.”);
Terminal.WriteLine(“3. My Heart.”);
}
void OnUserInput(string input)
{
print("The user is typing: " + input);
if (input == "menu")
{
ShowMainMenu("Hello User.");
RunMainMenu(input);
}
else if (currentScreen == Screen.MainMenu)
{
RunMainMenu(input);
}
else if (gameLevel == 1)
{
CheckForPassword1(input);
}
else if (gameLevel == 2)
{
CheckForPassword2(input);
}
else if (gameLevel == 3)
{
CheckForPassword3(input);
}
}
void RunMainMenu(string input)
{
gameLevel = 0;
currentScreen = Screen.MainMenu;
if (input == "1")
{
gameLevel = 1;
StartGame("You have chosen level " + gameLevel);
}
else if (input == "2")
{
gameLevel = 2;
StartGame("You have chosen level " + gameLevel);
}
else if (input == "3")
{
gameLevel = 3;
StartGame("You have chosen level " + gameLevel);
}
else
{
Terminal.WriteLine("You must choose from the options ");
Terminal.WriteLine("available.");
}
}
void StartGame(string input)
{
currentScreen = Screen.Password;
Terminal.ClearScreen();
Terminal.WriteLine("Please enter your Password");
}
void CheckForPassword1(string inputPassword)
{
if (inputPassword == "bin")
{
RunWinScreen("You Win!");
}
else if (inputPassword == "menu")
{
ShowMainMenu("Hello user.");
RunMainMenu(inputPassword);
}
else
{
Terminal.WriteLine("Try again.");
}
}
void CheckForPassword2(string inputPassword)
{
if (inputPassword == "shape")
{
RunWinScreen("You Win!");
}
else if (inputPassword == "menu")
{
ShowMainMenu("Hello user.");
RunMainMenu(inputPassword);
}
else
{
Terminal.WriteLine("Try again.");
}
}
void CheckForPassword3(string inputPassword)
{
if (inputPassword == "galactic")
{
RunWinScreen("You Win!");
}
else if (inputPassword == "menu")
{
ShowMainMenu("Hello user.");
RunMainMenu(inputPassword);
}
else
{
Terminal.WriteLine("Try again.");
}
}
void RunWinScreen(string congratulations)
{
currentScreen = Screen.Win;
gameLevel = 4;
Terminal.ClearScreen();
Terminal.WriteLine(congratulations + " Type menu to return");
}
}