2 hours for this... it was worth it in the end :)

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");
}

}

To embed code in a post, Perform the following steps:

  1. Start a line with 3 ‘`’ characters

  2. Paste your code

  3. Start a new line with 3’`’ characters.

If you look in the preview to the right of what you are typing, you will see that your pasted code with a light gray background.

Hope this helps.

Privacy & Terms