Hi There,
So I paused the video and went full steam for about 2 hrs. And I did it! I made the game work, BUT possibly the hardest way possible.
Once I pressed play on the video and saw how the instructor did it, it clicked! Think Methods! I have to think Method and it will only come naturally with more and more practice.
Check my Code! Its my take on it, I got there the hard way lol 2_Terminal_Hacker.zip (5.5 MB)
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hacker : MonoBehaviour {
//This is our Game State
int level;
String yourname;
enum Screen { YourName, MainMenu, NesPassword, SnesPassword, Win };
Screen currentScreen;
// Use this for initialization
void Start ()
{
EnterYourName();
}
void EnterYourName()//this handle YourName state
{
currentScreen = Screen.YourName;
Terminal.ClearScreen();
Terminal.WriteLine("What's your name?");
}
void ShowMainMenu(string greeting)
{
currentScreen = Screen.MainMenu;
Terminal.ClearScreen();
Terminal.WriteLine(greeting);
Terminal.WriteLine("Hack a console to get the gaming power?");
Terminal.WriteLine("Press 1 for power of NES");
Terminal.WriteLine("Press 2 for super power of SNES");
//Terminal.WriteLine("Press 3 for mega power of Sega Genesis");
Terminal.WriteLine("Select your console:");
}//this handle MainMenu state
void OnUserInput(string input) //This should decide how to handle user input not actually do it
{
if (currentScreen == Screen.YourName)
{
RunYourName(input);
}
else if (currentScreen == Screen.MainMenu)
{
RunMainMenu(input);
}
else if (currentScreen == Screen.NesPassword)
{
RunNesPassword(input);
}
else if (currentScreen == Screen.SnesPassword)
{
RunSnesPassword(input);
}
else if (currentScreen == Screen.Win)
{
RunWinScreen(input);
}
}
void RunMainMenu(string input)
{
// TODO handling differently depending on screen
if (input == "1")
{
level = (1);
StartLevel1Game("hack the NES");
}
else if (input == "2")
{
level = (2);
StartLevel2Game("hack the SNES");
}
else if (input == "3")
{
print("Player select level 3");
}
else if (input == "mario")
{
print("Play Mario lose song and display Lose page");
}
else if (input == "menu")
{
ShowMainMenu("Hello " + yourname);
currentScreen = Screen.MainMenu;
}
else
{
print("incorrect input");
Terminal.WriteLine("incorrect input");
}
} //This handle user input on MainMenu
void RunYourName(string input)
{
yourname = (input);
if (yourname == (yourname))
{
ShowMainMenu("Hello " + yourname);
}
} //This handle user input on YourName
void RunNesPassword(string input)
{
// TODO handling differently depending on screen
if (input == "menu")
{
ShowMainMenu("Hello Damien");
currentScreen = Screen.MainMenu;
}
else if (input == "Zelda")
{
ShowWinScreen("NES");
currentScreen = Screen.Win;
}
else
{
Terminal.WriteLine("Wrong Password");
}
}//This handle user input on Password on Level 1
void RunSnesPassword(string input)
{
if (input == "menu")
{
ShowMainMenu("Hello Damien");
currentScreen = Screen.MainMenu;
}
else if (input == "Pilotwings")
{
ShowWinScreen("SNES");
currentScreen = Screen.Win;
}
else
{
Terminal.WriteLine("Wrong Password");
}
}//This handle user input on Password on Level 2
void RunWinScreen(string input)
{
if (input == "menu")
{
ShowMainMenu("Hello " + yourname);
currentScreen = Screen.MainMenu;
}
else
{
Terminal.WriteLine("incorrect input");
}
}//This handle user input on WinScreen
void StartLevel1Game(string console)//this handle StartLevel1Game state
{
currentScreen = Screen.NesPassword;
Terminal.WriteLine("You have chosen to " + console);
Terminal.WriteLine("Please entre your password");
}
void StartLevel2Game(string console)//this handle StartLevel2Game state
{
currentScreen = Screen.SnesPassword;
Terminal.WriteLine("You have chosen to " + console);
Terminal.WriteLine("Please entre your password");
}
void ShowWinScreen(string console)
{
currentScreen = Screen.Win;
Terminal.WriteLine("Congratulations!");
Terminal.WriteLine("You now possess the Power of " + console + "!!!");
Terminal.WriteLine("");
Terminal.WriteLine("Type [menu] to start again...");
}//this handle Win state