Okay, more on my text game. I have made every room work just right, so now I just need to add a healthy sprinkling of items to the house. Easy enough, but what if the user wants to check his inventory?
Here is what I have come up with so far:
|
using System; for (int count = 0; count < inventory.Length-1; count++) |
Suppose I wanted to drop the keys. I would need to erase "keys" from the array, move everything after keys one space to the left, and reduce Array.Length by one. Any idea how I might do this?
Ryan AlfordPosted Aug 23, 2008, 11:49 AM
static void Main(string[] args)
{
//takes 5 items and turns them into a sentence
List
inventory.Add("matches");
inventory.Add("keys");
inventory.Add("a letter");
inventory.Add("rat poison");
inventory.Add("jerky");
Console.WriteLine("You are currently carrying:");
WriteItems(inventory);
Console.WriteLine("");
Console.WriteLine("What do you want to drop?");
string drop = Console.ReadLine();
Console.WriteLine("You are now carrying:");
inventory.Remove(drop);
WriteItems(inventory);
}
private static void WriteItems(List
{
for (int count = 0; count < inventory.Count; count++)
{
if (count != inventory.Count - 1)
{
Console.Write(inventory[count] + ", ");
}
else
{
Console.Write("and " + inventory[count]);
}
}
}
AnthonyPosted Aug 23, 2008, 11:09 PM
Wow. That works very nicely. In fact, that works perfectly. This is exactly what I needed. Thank you very much.