I am writing a large program that involves an Object called Player
. The Player definition is as follows:
public class Player
{
public static String name;
public static Item inventory[] = new Item[10];
public static int items;
/* ... */
public void addItem(String itemName, int itemType)
{
if ((items + 1) <= 10) {
inventory[items] = new Item(itemName, itemType);
items++;
}
}
public void removeItem(int x)
{
for (int i = x; i < items; i++)
inventory[i] = inventory[i+1];
}
}
I am adding inventory handling now because it's much easier than adding it later, but inventory
isn't going to be used until much later in development. I have no way to see if removeItem
works. I modified a function I wrote called strstrip
to get this... Would removeItem
work? If not, why?