Basically I know this is probably so simple.... But I want to have an if statement that checks if the entered word matches 3 values in an array... if they are then they get added to a list..
Below is the code that i'm talking about and also the code for the rest of the class.. (not the entire project, too big)
public static string PlayerSelectsItem(string word, object[] args)
{
if (word == "torch", "shield", "sword" )
{
GameEngine.Instance.RemoveItemFromRoom(word);
Inventory.AddItem(word);
Inventory.PrintItems();
Console.WriteLine();
return "MOVE_OR_PICK";
}
else
{
Console.WriteLine("The item does not exist");
}
return "";
}
<pre lang="cs">public class RoomThree:Room
{
public static string[] _availableItems = new string[] { "torch", "shield", "sword" };
public static ChatLine[] _lines = new ChatLine[]
{
new ChatLine("START", "Welcome to Room 3. There is a table with weapons and a phone ringing on it. " +
"I would suggest you answer it", "answer, answer phone", AnswerPhone),
new ChatLine("TABLE", "There are items on the table", "look, look table", LookTable),
new ChatLine("FOUND_ITEMS", "You looked at the table and there #AVAILABLE_ITEMS#.", "", PlayerSelectsItem),
new ChatLine("MOVE_OR_PICK", "Move towards the North door, or pick another item, there #AVAILABLE_ITEMS#", "pick+?", PlayerSelectsItem),
new ChatLine("MOVE_OR_PICK", "Move towards the North doorm or pick another item, there #AVAILABLE_ITEMS#", "move+?", GameEngine.Instance.PlayerMove),
new ChatLine("MOVE_OR_PICK", "Move towards the North doorm or pick another item, there #AVAILABLE_ITEMS#", "drop+?", PlayerDropsItem),
new ChatLine("", "", "pick+?, select+?, choose+?", PlayerSelectsItem),
new ChatLine("", "", "drop+?", PlayerDropsItem),
new ChatLine("", "", "move+?", GameEngine.Instance.PlayerMove)
};
public RoomThree()
: base("ROOM_THREE", _lines, "START", _availableItems)
{
}
private static string AnswerPhone(string word, object[] args)
{
Console.WriteLine();
Console.WriteLine("Hello human. My name is Sauron. I am the leader of this race. You have became a problem for me," +
" and for my race. But I see potential in you. I see a great warrior in you.. So I will offer you this deal...." +
"If you can get to me, I will offer you a commander role leading my army against the demons. But it will be tough, you" +
" will have to face very experienced fighting orcs and you will have to find your way to me.. But IF you SURVIVE." +
" I will make you my second in command. Now there are weapons on the table in front of you, and an orc in the other room." +
" Good luck. You will need it.");
Console.WriteLine();
return "TABLE";
}
private static string LookTable(string word, object[] args)
{
Console.WriteLine();
return "FOUND_ITEMS";
}
public static string PlayerSelectsItem(string word, object[] args)
{
if (word == "torch", "shield", "sword" )
{
GameEngine.Instance.RemoveItemFromRoom(word);
Inventory.AddItem(word);
Inventory.PrintItems();
Console.WriteLine();
return "MOVE_OR_PICK";
}
else
{
Console.WriteLine("The item does not exist");
}
return "";
}
public static string PlayerDropsItem(string word, object[] args)
{
if (Inventory.HasItem(word))
{
Inventory.RemoveItem(word);
GameEngine.Instance.DropItemInRoom(word);
Console.WriteLine("Item has been dropped");
}
else
{
Console.WriteLine("You don't have that item");
}
return "";
}
}</pre>