My Go on This Challange

I didn’t find the challange so hard. It’s probably due to my previous experiences in programming. I just needed to google how to use arrays in C# and I was good to go.

I needed to import System.Linq for the “Array.Contains(string)” method.

using System.Linq;

initializing some arrays.

string[] easyPasswords = {"word", "paper", "books", "radio", "pencil", "pen"};
string[] mediumPasswords = {"accountant", "deposit", "withdraw", "transmit", "robbery"};
string[] hardPasswords = {"handkerchief", "conscience", "millennium", "pharaoh", "convalescence"};

Small change to the OnUserInput method.

void OnUserInput(string input)
{
	if (input == "menu") // we can always go direct to main menu
	{
		ShowMainMenu();
	}
	else if (currentScreen == Screen.MainMenu)
	{
		RunMainMenu(input);
	}
	else if (currentScreen == Screen.Password)
	{
		RunPasswordScreen(input);
	}
}

My methods for checking the user input and telling them their result.

void RunPasswordScreen(string input)
	{
		if (level == 1 && easyPasswords.Contains(input))
		{
			PasswordSuccess();
		}
		else if (level == 2 && mediumPasswords.Contains(input))
		{
			PasswordSuccess();
		}
		else if (level == 3 && hardPasswords.Contains(input))
		{
			PasswordSuccess();
		}
		else
		{
			Terminal.WriteLine("");
			Terminal.WriteLine("Sorry, but the password is wrong!");
		}
	}

	void PasswordSuccess()
	{
		currentScreen = Screen.Win;
		Terminal.WriteLine("");
		Terminal.WriteLine("You've broken into the facility!");
	}
1 Like

Privacy & Terms