using System.Collections.Generic;
public static void Main()
var ui = new UserInterface();
var game = new SimpleGame(ui);
private UserInterface _ui;
private List<string> _inventory;
public SimpleGame(UserInterface ui)
_inventory = new List<string>();
_chest = new string[] { "Gold", "Sword", "Potion" };
_ui.Send("Welcome to the Treasure Hunt!");
_ui.Send("\nWhat would you like to do?");
_ui.Send("1. View Chest");
_ui.Send("2. Take Item");
_ui.Send("3. View Inventory");
string choice = _ui.RequestString("> ");
_ui.Send("Thanks for playing!");
_ui.Send("Invalid choice. Please select 1, 2, 3, or 4.");
_ui.Send("\nThe chest contains:");
for (int i = 0; i < _chest.Length; i++)
_ui.Send($"- {_chest[i]}");
_ui.Send("\nWhich item would you like to take?");
for (int i = 0; i < _chest.Length; i++)
_ui.Send($"{i + 1}. {_chest[i]}");
string choice = _ui.RequestString("> ");
if (int.TryParse(choice, out int index) && index > 0 && index <= _chest.Length)
string item = _chest[index - 1];
_ui.Send($"You took the {item}.");
_ui.Send("Invalid choice. Please select a valid item number.");
private void ViewInventory()
_ui.Send("\nYour inventory contains:");
if (_inventory.Count == 0)
_ui.Send("Your inventory is empty.");
foreach (string item in _inventory)
public void Send(string message)
Console.WriteLine(message);
public string RequestString(string message)
return Console.ReadLine();