|
|||||||
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
javax.microedition.lcdui.game.GameCanvas
example.pushpuzzle.PushPuzzleCanvas
class PushPuzzleCanvas
PushPuzzleCanvas displays the game board and handles key events. The PushPuzzle game logic and algorithms are separated into Board.java. PushPuzzleCanvas does not setup or use any Commands. Commands for each screen and listeners should be setup outside this class. PushPuzzleCanvas generates a SELECT_COMMAND when the current level is solved. Sequencing through screens is done in the PushPuzzle MIDlet.
PushPuzzleCanvas handles the reading, initialization, and sequencing of individual puzzle screens.
PushPuzzleCanvas uses the Score class to restore and save game levels and scores for each level. To display the scores use getScoreScreen. It will be initialized with the current scores. To select a new level use the getLevelScreen and gotoLevel methods.
PushPuzzleCanvas handled key events for LEFT, RIGHT, UP, and DOWN to move the pusher in the game board. Pointer pressed events are used to move the pusher to the target location (if possible).
Field Summary | |
---|---|
int |
TILE_GROUND
The index in the image of the Ground |
int |
TILE_PACKET
The index in the image of the Packet |
int |
TILE_PUSHER
The index in the image of the Pusher |
int |
TILE_STORE
The index in the image of the Store |
int |
TILE_WALL
The index in the image of the Wall |
Fields inherited from class javax.microedition.lcdui.game.GameCanvas |
---|
DOWN_PRESSED, FIRE_PRESSED, GAME_A_PRESSED, GAME_B_PRESSED, GAME_C_PRESSED, GAME_D_PRESSED, LEFT_PRESSED, RIGHT_PRESSED, UP_PRESSED |
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 | |
---|---|
PushPuzzleCanvas(PushPuzzle pushpuzzle,
Score s)
Construct a new canvas |
Method Summary | |
---|---|
void |
changeTheme()
Change themes. |
(package private) void |
closePlayer()
|
void |
destroy()
Cleanup and destroy. |
int |
getLevel()
Get the current level. |
javax.microedition.lcdui.Screen |
getLevelScreen()
Get a screen to let the user change the level. |
javax.microedition.lcdui.Screen |
getScoreScreen()
Return the Screen to display scores. |
boolean |
gotoLevel()
Go to the chosen Level. |
protected void |
hideNotify()
The canvas is being removed from the screen. |
void |
init()
Read the previous level number from the score file. |
protected void |
keyPressed(int keyCode)
Handle a single key event. |
protected void |
keyRepeated(int keyCode)
Handle a repeated arrow keys as though it were another press. |
boolean |
nextLevel(int offset)
Start the next level. |
void |
paint(javax.microedition.lcdui.Graphics g)
Paint the contents of the Canvas. |
(package private) void |
play(byte[] tune)
Play the simple tune supplied. |
protected void |
pointerPressed(int x,
int y)
Called when the pointer is pressed. |
void |
restartLevel()
Restart the current level. |
void |
run()
The main event processor. |
void |
setCommandListener(javax.microedition.lcdui.CommandListener l)
Add a listener to notify when the level is solved. |
protected void |
showNotify()
The canvas is being displayed. |
void |
undoMove()
Undo the last move if possible. |
(package private) void |
updateTilesNear(int loc,
int dir)
Queue a repaint for an area around the specified location. |
Methods inherited from class javax.microedition.lcdui.game.GameCanvas |
---|
flushGraphics, flushGraphics, getGraphics, getKeyStates |
Methods inherited from class javax.microedition.lcdui.Canvas |
---|
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, isDoubleBuffered, keyReleased, pointerDragged, pointerReleased, repaint, repaint, serviceRepaints, setFullScreenMode, sizeChanged |
Methods inherited from class javax.microedition.lcdui.Displayable |
---|
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setTicker, setTitle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final int TILE_GROUND
public final int TILE_PACKET
public final int TILE_STORE
public final int TILE_WALL
public final int TILE_PUSHER
Constructor Detail |
---|
public PushPuzzleCanvas(PushPuzzle pushpuzzle, Score s)
pushpuzzle
- the main MIDlets
- the score objectMethod Detail |
---|
public void init()
public void destroy()
public void changeTheme()
public void undoMove()
public void restartLevel()
public boolean nextLevel(int offset)
offset
- of the next level
public int getLevel()
public javax.microedition.lcdui.Screen getLevelScreen()
public boolean gotoLevel()
public javax.microedition.lcdui.Screen getScoreScreen()
protected void keyRepeated(int keyCode)
keyRepeated
in class javax.microedition.lcdui.Canvas
keyCode
- the key pressed.protected void keyPressed(int keyCode)
keyPressed
in class javax.microedition.lcdui.Canvas
protected void pointerPressed(int x, int y)
pointerPressed
in class javax.microedition.lcdui.Canvas
x
- location in the Canvasy
- location in the Canvaspublic void setCommandListener(javax.microedition.lcdui.CommandListener l)
setCommandListener
in class javax.microedition.lcdui.Displayable
l
- the object implementing interface CommandListenervoid updateTilesNear(int loc, int dir)
loc
- an encoded location from Board.getPusherLocationdir
- that the pusher moved and flag if it pushed a packetpublic void paint(javax.microedition.lcdui.Graphics g)
paint
in class javax.microedition.lcdui.game.GameCanvas
g
- Graphics context to paint to.protected void showNotify()
showNotify
in class javax.microedition.lcdui.Canvas
protected void hideNotify()
hideNotify
in class javax.microedition.lcdui.Canvas
public void run()
run
in interface java.lang.Runnable
void play(byte[] tune)
void closePlayer()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |