adventure.items
Interface Item

All Known Implementing Classes:
Batteries, Flashlight

public interface Item

This interface specifies how all Item classes in the game must be built. All items must have the methods declared here defined within their classes or the game will not compile. Inheriting from this class does not limit items to these methods however; more can easily be added.

To create another item, create a new class that implements the Item interface. Make sure your class has all these methods.


Method Summary
 void draw(GameState game, java.awt.Graphics g, int windowWidth, int windowHeight, int itemIndex)
          Draws the item to the screen at position windowWidth - 100 * itemIndex, windowHeight - 100.
 java.lang.String getName()
          Returns the name of this item object as a String.
 void outputDescription(GameState game, OutputPanel output)
          Prints text describing this item to the output panel.
 boolean takeAction(GameState game, OutputPanel output, java.lang.String verb, java.lang.String noun)
          This method is called when the user enters a command.
 

Method Detail

getName

java.lang.String getName()
Returns the name of this item object as a String. Every item in the game must have a unique, case-insensitive name.

Students may often call this method.

Returns:
the name of this item object

outputDescription

void outputDescription(GameState game,
                       OutputPanel output)
Prints text describing this item to the output panel. Students should give every item an interesting description.

It would be uncommon for students to call this method.

Parameters:
game - the GameState object that is running / keeping track of this game
output - the output panel where text will be added

takeAction

boolean takeAction(GameState game,
                   OutputPanel output,
                   java.lang.String verb,
                   java.lang.String noun)
This method is called when the user enters a command. This item has the opportunity to process the user's command. Students can add commands to items by adding code to this method.

This method should return false if the command was not processed here. It should return true if the command was processed here.

It would be uncommon for students to call this method.

Parameters:
game - the GameState object that is running / keeping track of this game
output - the output panel where text will be added
verb - the verb of the action, such as "get"
noun - the noun of the action, such as "batteries"
Returns:
true if the action was handled in this method, false otherwise

draw

void draw(GameState game,
          java.awt.Graphics g,
          int windowWidth,
          int windowHeight,
          int itemIndex)
Draws the item to the screen at position windowWidth - 100 * itemIndex, windowHeight - 100. This method is only needed if you are using item images in your game.

It would be uncommon for students to call this method.

Parameters:
game - the GameState object that is running / keeping track of this game
g - the Graphics object to do the drawing
windowWidth - the width of the window
windowHeight - the height of the window
itemIndex - the relative position of this item (0 = first, rightmost)