|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.microedition.lcdui.Displayable
javax.microedition.lcdui.Canvas
example.wormgame.WormPit
public class WormPit
The WormPit contains a Worm and some WormFood. The Worm will slither around the pit in search of WormFood. If the Worm eats it will grow in length. The Worm will be killed if it attempts to slither past the edge of the pit or if it eats itself.
Field Summary | |
---|---|
static int |
CELL_SIZE
Size of a cell for worm rendering. |
(package private) static int |
CellHeight
Current screen height in cells. |
(package private) static int |
CellWidth
Current screen size in cells. |
(package private) static int |
DRAW_COLOUR
Color for drawing worm cells. (0x000000) |
(package private) static int |
ERASE_COLOUR
Color for erasing worm cells. (0xffffff) |
(package private) static int |
FOOD_COLOUR
Color for target food object. (0x00ff00) |
(package private) static byte |
MAX_LEVELS
Maximum number of difficulty levels. (10) |
(package private) static int |
TEXT_COLOUR
Color for text objects. (0xff0000) |
Fields inherited from class javax.microedition.lcdui.Canvas |
---|
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP |
Constructor Summary | |
---|---|
WormPit()
Default constructor for worm pit. |
Method Summary | |
---|---|
void |
createAudioPlayer()
Create an audio player. |
void |
destroyAudioPlayer()
Destroy the audio player. |
void |
destroyGame()
Destroy the entire game. |
int |
getLevel()
Get the difficulty level. |
int |
getScore()
Get the score of this game. |
protected void |
hideNotify()
Notification handler when canvas hidden. |
(package private) static boolean |
isInBounds(int x,
int y)
Returns true if the given point is within the bounds of the worm pit. |
void |
keyPressed(int keyCode)
Handle keyboard input. |
void |
mute()
if audio is on - mute |
void |
paint(javax.microedition.lcdui.Graphics g)
Paint the worm pit and its components |
(package private) void |
restart()
Restart the game. |
void |
run()
The main execution loop. |
void |
setDestroyed(boolean destroyGame)
Set Destroyed state in order to undestroy game after pause. |
void |
setLevel(int level)
Set the difficulty level. |
void |
unMute()
if audio is stopped - restart it |
Methods inherited from class javax.microedition.lcdui.Canvas |
---|
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, isDoubleBuffered, keyReleased, keyRepeated, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, setFullScreenMode, showNotify, sizeChanged |
Methods inherited from class javax.microedition.lcdui.Displayable |
---|
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setCommandListener, setTicker, setTitle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static int CellWidth
static int CellHeight
static final byte MAX_LEVELS
static final int FOOD_COLOUR
static final int TEXT_COLOUR
static final int ERASE_COLOUR
static final int DRAW_COLOUR
public static final int CELL_SIZE
Constructor Detail |
---|
public WormPit()
Method Detail |
---|
public void setLevel(int level)
level
- value of new level requestedgetLevel()
public int getLevel()
setLevel(int)
public int getScore()
static boolean isInBounds(int x, int y)
x
- x coordinate of point to check (0 - CellWidth)y
- y coordinate of point to check (0 - CellHeight)
void restart()
public void keyPressed(int keyCode)
keyPressed
in class javax.microedition.lcdui.Canvas
keyCode
- pressed key is either Canvas arrow key (UP,
DOWN, LEFT, RIGHT) or simulated with KEY_NUM (2, 8, 4,6).public void paint(javax.microedition.lcdui.Graphics g)
paint
in class javax.microedition.lcdui.Canvas
g
- graphics object to be renderedprotected void hideNotify()
hideNotify
in class javax.microedition.lcdui.Canvas
public void run()
run
in interface java.lang.Runnable
public void destroyGame()
public void setDestroyed(boolean destroyGame)
public void destroyAudioPlayer()
public void createAudioPlayer()
public void mute()
public void unMute()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |