Comp 170 Lab 7 - World of Zuul TAKE command, March 15

I've added partial support to the Zuul 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.

The zipfile for the modified Zuul is here

The first thing I did 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 (of Item objects), and also an ArrayList 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. The main part of your lab is to implement doTake. It should verify that the user entered a proper TAKE command, verify that the object in question is in the room (ie is on currentRoom.items), and then move the item from the room to inventory and print a final response for the user.

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.

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

The above is worth 8 points out of 10. For the last two points (plus possibly one extra credit), 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 Game.java and Room.java files.