Got bored wrote whole game

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hacker : MonoBehaviour
{
// Start is called before the first frame update
private

enum GameStates { Start, GuessPassword, GameEnded}
int GameLevel,tries;
GameStates GameState; 
string[][] passwords = new string[3][];
string pwd;



void Start()
{
    passwords[0] = new string[5] { "Book", "Shelf", "Quiet", "Librarian", "Fine" };
    passwords[1] = new string[5] { "Handcuff", "Copper", "Arrested", "Station", "Chase" };
    passwords[2] = new string[5] { "Telescope", "Galaxy", "Astronaut", "Rocket", "Uranus"};

    print("Hello Console");
    ShowMainMenu();
    GameLevel = 0;
}

string Anagram(string word)
{
    string a="";
    char c;
    int x, l,sp;
    char [] t, d;
    l = word.Length;
    t = word.ToCharArray();
    d = new char[l];
    for(x=0;x<l;x++)
    {
        d[x] = '\0';
    }
    for(x=0;x<l;x++)
    {
        sp = Random.Range(0, l - 1);
        if (d[sp] != '\0')
        {
            if ((sp & 1) == 0)
            {
                //even number search forward for next free slot
                while (d[sp] != '\0')
                {
                    sp++;
                    if (sp >= l)
                    {
                        sp = 0;
                    }
                }
            }
            else
            {
                //odd search backward for next free slot
                while (d[sp] != '\0')
                {
                    sp--;
                    if (sp < 0)
                    {
                        sp = l-1;
                    }
                }
            }
        }
        d[sp] = t[x];
    }

    for (x = 0; x < l; x++)
    {
        a += d[x];
    }
    //a = d.ToString(); //Didn't work returned System.Char();
    return a;
}

// Update is called once per frame
int ProcessStartInput(string input)
{
    int r,l;
    string a,place,m;
    string [] pa;
    r = 0;
    place = "";
    switch (input)
    {
        case "1":
            r = 1;
            Terminal.WriteLine("You choose to hack the Libray");
            place = "Library";
            break;
        case "2":
            r = 2;
            Terminal.WriteLine("You choose to hack the Police");
            place = "Police";
            break;
        case "3":
            r = 3;
            Terminal.WriteLine("You choose to hack NASA");
            place = "NASA";
            break;
            default:
            Terminal.WriteLine("Invalid Choice");
        break;
    }
    if (r > 0)
    {
        pa = passwords[r-1];
        l = pa.GetUpperBound(0);
        pwd = pa[Random.Range(0,l)];
        a = Anagram(pwd);
        m = place + " Login :";
        Terminal.WriteLine(place + " Login :");
        Terminal.WriteLine("CLUE : " + a);
        Terminal.WriteLine("Enter pwd > ");
    }
    return r;
}

bool CheckPassword(string Guess)
{
    return (Guess == pwd);
}

void OnUserInput(string input)
{
    GameStates LastGameState = GameState;
    if(input !="menu")
        {
        switch (GameState)
        {
            case GameStates.Start:
                if(ProcessStartInput(input)>0)
                {
                    GameState = GameStates.GuessPassword;
                    tries = 0;
                }
                break;
            case GameStates.GuessPassword:
                if(CheckPassword(input))
                {
                    Terminal.WriteLine("ACCESS GRANTED");
                    GameState = GameStates.GameEnded;
                }
                else
                {
                    tries++;
                    int tr = 3 - tries;
                    Terminal.WriteLine("INCORRECT PASSWORD " + tr + " tries remaining.");
                    if (tries > 2)
                    {
                        Terminal.WriteLine("ACCESS DENIED");
                        GameState = GameStates.GameEnded;   
                    }
                    if(GameState == GameStates.GameEnded)
                    {
                        Terminal.WriteLine("Press Enter To Continue");
                    }
                }
                break;
            case GameStates.GameEnded:
                ShowMainMenu();
                break;
        }
    }else{
        ShowMainMenu();
    }
}

void ShowMainMenu()
{
    Terminal.ClearScreen();
    Terminal.WriteLine("Welcome To Net Runner 5000");
    Terminal.WriteLine("1 Hack Library");
    Terminal.WriteLine("2 Hack Police Station");
    Terminal.WriteLine("3 Hack NASA");
    Terminal.WriteLine("Enter your Selection : ");
    GameState = GameStates.Start;
}
void Update()
{
    
}

}

1 Like

Privacy & Terms