Solo Challenge

Attempt at the solo challenge, spend about 10 minutes… Not sure how efficient it is, but it works.

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

public class Hacker : MonoBehaviour
{

    // Game state
    int level;
    string onePass = "donkey";
    string twoPass = "elephant";
    string currPass;
    enum Screen { MainMenu, Password, Win};
    Screen currentScreen;


    // 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("");
        Terminal.WriteLine("Press 1 for the local library");
        Terminal.WriteLine("Press 2 for the police station");
        Terminal.WriteLine("Press 3 for NASA");
        Terminal.WriteLine("");
        Terminal.WriteLine("Enter your selection: ");
    }

    void OnUserInput(string input)
    {
       if (input=="menu")
        {
            ShowMainMenu();
        }
       else if (currentScreen == Screen.MainMenu)
        {
            RunMainMenu(input);
        }
       else if (currentScreen == Screen.Password)
        {
            CheckPass(input);
        }

    }

    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 if (input == "007")
        {
            Terminal.WriteLine("");
            Terminal.WriteLine("Welcome back, Mr. Bond.");
        }
        else
        {
            Terminal.WriteLine("Please select a valid level.");
        }
    }

    void StartGame()
    {
        currentScreen = Screen.Password;
        Terminal.WriteLine("You have chosen level " + level);
        Terminal.WriteLine("Please enter your password: ");

        if (level == 1) { currPass = onePass; }
        else if (level ==2) { currPass = twoPass; }


    }

    void CheckPass(string input)
    {
        if (input == currPass)
        {
            Terminal.WriteLine("You win!!!");
        }
        else
        {
            Terminal.WriteLine("Try again: ");
        }
    }
}

1 Like

Incredible job completing the challenge! 10 mins is really good!

Privacy & Terms