Random.Range

using UnityEngine;

public class Hacker : MonoBehaviour
{

int level;
string password;
string[] level1Password = {"GUN", "PASSWORD", "SUSPECT","DNA","ENEMY" };
string[] level2Password = { "MILLIONS", "JACKPOT", "BIG WIN", "MONEY", "FINANCIAL FREEDOM" };
string[] level3Password = { "SPECIAL FORCES", "CRIME", "SPECIALIZED WEAPONS", "SNIPER", "COORDINATED ACTION" };
enum Screen {MainMenu, Password, Win };
Screen currentScreen = Screen.MainMenu;


// Start is called before the first frame update
void Start()
{
    ShowMainMenu();
}


void ShowMainMenu()
{
    currentScreen = Screen.MainMenu;
    Terminal.ClearScreen();
    Terminal.WriteLine("What would you like to hack into?");
    Terminal.WriteLine("Press 1 for the FBI");
    Terminal.WriteLine("Press 2 for the EURO JACKPOT");
    Terminal.WriteLine("Press 3 for the NASA");
    Terminal.WriteLine("Enter your selection: ");
}

void OnUserInput(string input)
{
    if(input == "menu")
    {
        level = 0; 
        ShowMainMenu();
    }

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

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

}

void RunMainMenu(string input)
{

    bool isValidLevelNumber = (input == "1"|| input =="2"|| input == "3");
    if (isValidLevelNumber)
    {
        level = int.Parse(input);
        StartGame();
    }
    else if (input == "3")
    {
        password = level3Password[3];
        StartGame();
    }
    else if (input == "why not")
    {
        Terminal.WriteLine("because");
    }
    else
    {
        Terminal.WriteLine("Wrong choose, try again later");
    }
}

void StartGame()
{
    currentScreen = Screen.Password;
    Terminal.ClearScreen();
    switch (level)
    {
        case 1:
            int index1 = Random.Range(0, level1Password.Length);
            password = level1Password[index1];
            break;
        case 2:
            int index2 = Random.Range(0, level2Password.Length);
            password = level2Password[index2];
            break;
        case 3:
            int index3 = Random.Range(0, level3Password.Length);
            password = level3Password[index3];
            break;
        default:
            Debug.LogError("Invalid level number");
            break;

    }
    Terminal.WriteLine("Please enter your password: ");
}

void Password(string input)
{
    if (input == password)
    {
        Terminal.WriteLine("Congratulations you are in");
        Terminal.WriteLine("All data is yours :)");
    }
    else
    {
        Terminal.WriteLine("Sorry wrong password. Please try again");
    }
}

}

Privacy & Terms