My code so far, working great :)

cu2_s02_arrays_of_variables

#1

Hi all,

Here is what I have so far! It’s been pretty fun putting this together :smiley:

using UnityEngine;
using System.Collections;

public class Hacker : MonoBehaviour
{
    // Game configuration data
    string[] SexPasswords = { "female", "male", "intersex", "genes", "body" };
    string[] SexualityPasswords = { "lesbian", "gay", "bisexual", "pansexual", "asexual" };
    string[] GenderPasswords = { "cisgender", "transgender", "demiboy", "genderfluid", "nonbinary" };

    // Game state
    string Level;
    enum Screen { MainMenu, Password, Win };
    Screen CurrentScreen;
    string Password;

    // Initialization
    void Start()
    {
        ShowMainMenu();
    }

    void ShowMainMenu()
    {
        CurrentScreen = Screen.MainMenu;
        Terminal.ClearScreen();
        Terminal.WriteLine("What would you like to hack today?");
        Terminal.WriteLine("");
        Terminal.WriteLine("Press 1 to hack Sex");
        Terminal.WriteLine("Press 2 to hack Sexuality");
        Terminal.WriteLine("Press 3 to hack Gender");
        Terminal.WriteLine("");
        Terminal.WriteLine("Enter your selection:");
        Terminal.WriteLine("");
    }

    void OnUserInput(string input)
    {
        if (input == "menu")
        {
            ShowMainMenu(); // We can always go back to main menu
        }

        else if (CurrentScreen == Screen.MainMenu)
        {
            RunMainMenu(input);
        }

        else if (CurrentScreen == Screen.Password)
        {
            CheckPassword(input);
        }
    }

    void RunMainMenu(string input)
    {
        if (input == "1")
        {
            Level = "Sex";
            Password = SexPasswords[0];
            StartGame();
        }

        else if (input == "2")
        {
            Level = "Sexuality";
            Password = SexualityPasswords[0];
            StartGame();
        }

        else if (input == "3")
        {
            Level = "Gender";
            Password = GenderPasswords[0];
            StartGame();
        }

        else if (input == "69")
        {
            Terminal.WriteLine("Not that kind of sex, you perv.");
            Terminal.WriteLine("");
        }

        else
        {
            Terminal.WriteLine("Please select something to hack.");
            Terminal.WriteLine("");
        }
    }

    void StartGame()
    {
        CurrentScreen = Screen.Password;
        Terminal.ClearScreen();
        Terminal.WriteLine("You have chosen to hack " + Level + ".");
        Terminal.WriteLine("");
        Terminal.WriteLine("Please enter your password:");
        Terminal.WriteLine("");
    }

    void CheckPassword(string input)
    {
        if (input == Password)
        {
            Terminal.WriteLine("Well done!");
        }

        else
        {
            Terminal.WriteLine("Wrong password. Try again.");
        }
    }
}