Script Classes for Adventure Games/Inventory Class
Author: Jeff Stephenson
The Inventory Class
The Inventory class is a List of all the objects (see the InvItem class) which may be collected by ego in a game. There are two steps to setting up the inventory.
First, in the main header file for the game (typically game.sh), create an enum statement listing all the symbols which you will use to refer to the inventory items. In order to avoid name conflicts, these are traditionally the names preceded by an 'i': a rock might be referred to as "iRock".
Next, in the main game file (the file in which you define your instance of Game), you create the instances of InvItem which are the inventory items. These are added to the Inventory (whose ID is in the global variable inventory) in the init: of the game after the (super init:). The InvItems must be added to the inventory in the order in which they are listed in the enum statement above (a block copy works wonders...).
From now on you may get the object ID of any InvItem with the at: method of Inventory by using the symbol for the item defined in the enum statement. If you wanted to move the rock from its current position to room number 15, you could write
Code:((inventory at:iRock) moveTo:15)
The get:, put:, and has: methods of the Ego class use the enumed symbols rather than the object ID. Thus, to see if ego has the rock, you would write
showSelf: whomDisplay the items possessed by whom. This is done by putting up a window with all currently possessed items in it. By clicking the mouse on an item, the user may see a picture of it and receive a more detailed description of it. Ego's possessions are done withCode:(inventory showSelf:ego)
saidMe =Return the object ID of the first item in the inventory whose said property matches what the user typed.