My Solo Code

Here is what I’ve done during my solo challenge

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

public class Hacker : MonoBehaviour
{
    //Game state
    int level;
    enum Screen {MainMenu, Password, Win};
    Screen currentScreen;
    string password;

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

    void ShowMainMenu()
    {
        currentScreen = Screen.MainMenu;
        password = "";
        level = 0;
        Terminal.ClearScreen();
        Terminal.WriteLine("What are we going to hack today?\n");
        Terminal.WriteLine("Chose 1 if you would like to hack our  local school");
        Terminal.WriteLine("Chose 2 if you would like to hack the  police station");
        Terminal.WriteLine("Chose 3 if you would like to hack CSI");    
    }

    void OnUserInput(string input)
    {
        if (input == "menu" || input == "Menu" || input == "MENU")
        {
            ShowMainMenu();
        }
        else if (currentScreen == Screen.MainMenu)
        {
            RunMainMenu(input);
        }
        else if(currentScreen == Screen.Password)
        {
            CheckPassword(input);
        }
        else if(currentScreen == Screen.Win)
        {
            if(input == "y")
            {
                ShowMainMenu();
            }
            else if(input == "n")
            {
                Terminal.ClearScreen();
                Terminal.WriteLine("See you soon!");
            }
            else 
            {
                Terminal.WriteLine("Please try again");
            }
        }
    }

    void RunMainMenu(string input)
    {
        if (input == "1")
        {
            level = 1;
            StartGame();
        }
        else if (input == "2")
        {
            level = 2;
            StartGame();
        }
        else if (input == "3")
        {
            level = 3;
            StartGame();
        }
        else
        {
            Terminal.WriteLine("Please select a valid level:");
        }
    }

    void StartGame()
    {
        currentScreen = Screen.Password;
        Terminal.ClearScreen();
        Terminal.WriteLine("You have chosen level " + level);

        if(level == 1)
        {
            password = "Teacher";
            Terminal.WriteLine("Please enter password to local school:");
        }
        else if(level == 2)
        {
            password = "Policeman";
            Terminal.WriteLine("Please enter password to Police Department:");
        }
        else if (level == 3)
        {
            password = "SecretAgent";
            Terminal.WriteLine("Please enter password to CSI:");
        }

    }
    void CheckPassword(string inputPassword)
    {
        if (level == 1)
        {
            if (inputPassword == password)
            {
                EndGane();
            }
            else
            {
                Terminal.WriteLine("Incorrect. Please try again");
            }
        }

        if (level == 2)
        {
            if (inputPassword == password)
            {
                EndGane();
            }
            else
            {
                Terminal.WriteLine("Incorrect. Please try again");
            }
        }

        if (level == 3)
        {
            if (inputPassword == password)
            {
                EndGane();
            }
            else
            {
                Terminal.WriteLine("Incorrect. Please try again");
            }
        }

    }

    void EndGane()
    {
        currentScreen = Screen.Win;
        Terminal.ClearScreen();

        if (level == 1)
        {
            Terminal.WriteLine("Congratulations, you have just hacked  local School!");
        }
        else if (level == 2)
        {
            Terminal.WriteLine("Congratulations, you have just hacked  the Police Department!");
        }
        else if (level == 3)
        {
            Terminal.WriteLine("Congratulations, you have just hacked  the CSI!");
        }

        Terminal.WriteLine("\n");
        Terminal.WriteLine("Would you like to play again?");
        Terminal.WriteLine("y or n");
    }

    // Update is called once per frame
    void Update()
    {

    }
}
1 Like

Privacy & Terms