Switch statement

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = System.Random;

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:
            password = level1Password[0];
            break;
        case 2:
            password = level2Password[0];
            break;
        case 3:
            password = level3Password[0];
            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