|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectexample.wormgame.Worm
public class Worm
A Worm is a combination of one or more WormLinks. The first WormLink is the physical tail of the worm. The last WormLink is the physical head of the worm. As the worm moves, it adds one space to the head and then removes one from the tail. If the worm eats a piece of food, the head adds one space but the tail will not remove one. In this manner, the worm will grow outward from its head.
Field Summary | |
---|---|
static byte |
DOWN
|
static byte |
LEFT
|
static byte |
RIGHT
|
static byte |
UP
|
Constructor Summary | |
---|---|
Worm(WormPit pit)
|
Method Summary | |
---|---|
boolean |
contains(int x,
int y)
Returns true if the worm contains the given cell coordinate. |
void |
drawLink(javax.microedition.lcdui.Graphics g,
int x1,
int y1,
int x2,
int y2,
int len)
Draw a worm link. |
void |
eat()
Signals the worm to eat a food item |
int |
getX()
Get the X coordinate of the cell that contains the worm's head. |
int |
getY()
Get the Y coordinate of the cell that contains the worm's head. |
void |
moveOnUpdate()
Schedule the worm for growth. |
void |
paint(javax.microedition.lcdui.Graphics g)
Draw the entire worm. |
void |
regenerate()
Regenerate the worm in its initial position. |
void |
setDirection(byte direction)
Change the direction of the worm. |
void |
update(javax.microedition.lcdui.Graphics g)
Update the worm. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte DOWN
public static final byte LEFT
public static final byte RIGHT
public static final byte UP
Constructor Detail |
---|
public Worm(WormPit pit)
Method Detail |
---|
public void regenerate()
public void setDirection(byte direction)
public void moveOnUpdate()
public void update(javax.microedition.lcdui.Graphics g) throws WormException
WormException
public void drawLink(javax.microedition.lcdui.Graphics g, int x1, int y1, int x2, int y2, int len)
public void paint(javax.microedition.lcdui.Graphics g)
public void eat()
public int getX()
public int getY()
public boolean contains(int x, int y)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |