Challenge completed on my own

Managed to not only complete this challenge on my own but added a few features. I put in a sort of lives system where you only get a certain number of tries depending on the difficulty and each failed attempt reduces that number and I added a game over screen.

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

public class Hacker : MonoBehaviour
{
    // Game configuration data
    string[] level1Passwords = { "books", "aisle" };
    //Game state
    int level;
    int lives;
    string password;
    enum Screen { MainMenu, Confirmation, Password, Win, lose};
    Screen currentScreen;
    
    // Use this for initialization
    void Start()
    {
        ShowMainMenu();

    }

    void ShowMainMenu()
    {
        currentScreen = Screen.MainMenu;
        level = 0;

        Terminal.ClearScreen();
        Terminal.WriteLine("What would you like to hack into?");
        Terminal.WriteLine("Press 1 for the local library");
        Terminal.WriteLine("Press 2 for the police station");
        Terminal.WriteLine("Press 3 for NASA");
        Terminal.WriteLine("Enter your Selection:");
    }

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

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

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

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

    void RunMainMenu(string inputMainMenu)
    {
        if (inputMainMenu == "1")
        {
            level = 1;
            lives = 4;
            password = "book";
            StartGame("Public Library main Directory");
        }

        else if (inputMainMenu == "2")
        {
            level = 2;
            lives = 3;
            password = "handcuffs";
            StartGame("Police Department database");
        }

        else if (inputMainMenu == "3")
        {
            level = 3;
            lives = 2;
            password = "andromeda";
            StartGame("Welcome to NASA");
        }

        else if (inputMainMenu == "Torchwood")
        {
            currentScreen = Screen.Confirmation;
            Terminal.WriteLine("Are you sure?");
        }

        else
        {
            Terminal.WriteLine("Please try again");
        }
    }

    void AskConfirmation(string inputConfirm)
    {
        if (inputConfirm == "yes")
        {
            level = 4;
            lives = 1;
            password = "gallifrey";
            StartGame("Welcome to the UNIT mainframe");
        }

        else if (inputConfirm == "no")
        {
            ShowMainMenu();
        }

        else
        {
            Terminal.WriteLine("Please try again");
        }
    }

    void StartGame(string levelName)
    {
        currentScreen = Screen.Password;
        Terminal.WriteLine(levelName);
        Terminal.WriteLine("Please enter your password:");
    }
    
    void enterPassword(string attempt)
    {
        if (attempt == password)
        {
            WinGame();
        }

        else
        {
            lives -= 1;
            if (lives > 0)
            {
                Terminal.WriteLine("Access Denied");
                Terminal.WriteLine("Number of tries remaining " + lives);
                Terminal.WriteLine("Please enter your password:");
            }
            else if(lives <= 0)
            {
                gameOver();
            }
        }
    }

    void gameOver()
    {
        currentScreen = Screen.lose;
        int counter = 10;
        do
        {
            Terminal.WriteLine("GAME OVER MAN! GAME OVER!");
            counter -= 1;
        }
        while (counter > 0);

        Terminal.WriteLine("Type \"menu\" to return to the main menu");
    }

    void WinGame()
    {
        currentScreen = Screen.Win;
        Terminal.WriteLine("Access Granted");
    }
}

1 Like

Classic GO screen :3

This is really neat, nice work!

Reminds me of the Fallout 3 and New Vegas style terminal hacking. Nice job!

Privacy & Terms