Comp 170 Lab 6 - World of Zuul TAKE command

I've added partial support to the Chapter-7 Zuul-better game for "carryable" items that the player can pick up (TAKE) and drop. The implementation of TAKE is unfinished; you are to complete that. This will involve one minor new method in the Room class (see below), but everything else will be part of the Game class.

Here is the revised project zip file.

You are also to add at least two new Rooms and at least two new Items, one in a new Room and one in an existing Room.

The main change I made was to add the class Item. An Item primarily has a description, which is a String, although a weight field is there as well. I then added a field items to each Room, consisting of an ArrayList<Item>, and also an ArrayList<Item> inventory to the class Game representing the Items that you're currently walking around with. Note that this is one ArrayList per room plus one for the player.

I added the command words TAKE and DROP to the Parser and CommandWords classes, and adjusted the processCommand method to call doTake and doDrop, respectively, when the user enters these.

Finally, I provided a complete implementation of doDrop. Use that as a model as you implement doTake. It should

You will need to add an accessor to the Room class to get this to work, because doTake will need access to the entire list currentRoom.items, not just the capability to add one item to it (or even the capability to delete one item from it). I suggest a method Room.getItems() that returns items.

One minor issue is that in the TAKE and DROP commands the name of the Item is given, which is a String. The name is not the same as the item itself, of type Item. Hence the need for findByName().

When the game starts up, some items are scattered around some of the rooms, and the initial inventory has a few Item objects on it.

The above is worth 8 points out of 10. For the last two points, do the following. First, initialize each Item with a weight > 0 (I did a few already). Then have doTake check that the total weight of the new item + inventory is less than or equal to MAXWEIGHT; disallow attempts to pick up more than that. Note that the total weight here, if item is the item requested, is

    item.getWeight() + totalWeight(inventory)
If something is too heavy, say so and leave the Item where it is.

For convenience, I added commands LOOK to repeat the room's description (perhaps after you've TAKEn or DROPped something) and INVENTORY to list what you're currently carrying around.

Email me your completed project.