example.wormgame
Class WormFood

java.lang.Object
  extended by example.wormgame.WormFood

public class WormFood
extends java.lang.Object

WormFood is a food item that the worm can eat. It is placed at a pseudo randomly generated location in the pit.


Constructor Summary
WormFood(WormPit pit)
          Constructor for worm food object.
 
Method Summary
 int getX()
          Get the X coordinate of the cell that contains the food item.
 int getY()
          Get the Y coordinate of the cell that contains the food item.
 boolean isAt(int cx, int cy)
          Returns true if the food item is at the given cell.
 void paint(javax.microedition.lcdui.Graphics g)
          Paint the piece of food.
 void regenerate()
          Regenerate the food item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WormFood

public WormFood(WormPit pit)
Constructor for worm food object.

Parameters:
pit - pit to which the food is associated. (unused currently)
Method Detail

isAt

public boolean isAt(int cx,
                    int cy)
Returns true if the food item is at the given cell.

Parameters:
cx - x coordinate of cell to test
cy - y coordinate of cell to test
Returns:
true, if the food is at the cell coordinate

getX

public int getX()
Get the X coordinate of the cell that contains the food item.

Returns:
x coordinate of food cell location

getY

public int getY()
Get the Y coordinate of the cell that contains the food item.

Returns:
y coordinate of food cell location

regenerate

public void regenerate()
Regenerate the food item. Whenever the worm eats a piece of food, this method is called.


paint

public void paint(javax.microedition.lcdui.Graphics g)
Paint the piece of food.

Parameters:
g - graphics object to receive rendering of food object