|
|||||||||||
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
bluegammon.gui.PopupCanvas
bluegammon.gui.BoardCanvas
Singleton class handling all graphical details of a backgammon view.
There can only be one BoardCanvas
per device, thus
the singleton pattern.
BoardCanvas
handles the BackGammon board gui view.
Contains functionality for signalling gui changes on
user interaction. Uses a Board
instance for
representation of gui state of the backgammon board.
The BoardCanvas
also contains drawing primitives for
the backgammon board.
BoardMediator
,
BoardState
Field Summary | |
static javax.microedition.lcdui.Command |
CMD_EXIT
Exit command |
static javax.microedition.lcdui.Command |
CMD_UNDO
Undo command |
static float |
PIECE_Z
The 3d z depth of a piece lying on backgammon board |
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 |
Method Summary | |
void |
addPiece(boolean white,
int index)
Adds a new piece to the canvas |
void |
addWinningPieceAnimation(boolean white,
WinnerAnim winAnim)
Adds a piece animation when there is a winner. |
void |
allowInteraction(boolean allow)
Sets whether the canvas accepts any interaction or not. |
void |
commandAction(javax.microedition.lcdui.Command c,
javax.microedition.lcdui.Displayable d)
Handles command invokations from SoftButtonControl . |
void |
commitRepaint()
Committs all repaint request in an actual repaint. |
void |
consumeDiceValue(int diceVal)
Called from logic when user has made a move using specified dice value. |
void |
cursorBackIndex()
Steps backward amongst cursor indices. |
void |
cursorNearestIndex(int oldIndex,
int oldTarget)
Moves to nearest cursor index after a change in possible moves. |
void |
cursorNextIndex()
Steps forward amongst cursor indices. |
void |
cursorSwapSide()
Moves cursor to nearest matching cursor index on opposite side of board, given current cursor position. |
void |
drawPiece(int x,
int y,
float angle,
boolean horizTilt,
float dz,
boolean white,
javax.microedition.lcdui.Graphics g)
Draws a piece on specified coordinates. |
void |
drawPiece3D(int x,
int y,
float angle,
boolean horizTilt,
float dz,
boolean white,
Context3D c3d,
javax.microedition.m3g.Graphics3D g3d)
Draws a piece on specified coordinates. |
void |
finishGame(boolean white,
int pieces,
int pts)
Setups gui when there is a winner. |
int |
getBoardHeight()
Returns the actual height of the board in pixels |
javax.microedition.lcdui.Image |
getBoardImage()
Returns an image of a clean backgammon board (without pieces). |
int |
getCurrentCursorIndex()
Returns current cursor index of possible moves. |
static BoardCanvas |
getInstance()
Returns singleton instance. |
int |
getPieces(boolean white,
int index)
Returns number of pieces on specified index of specified color |
int |
getPieces(int index)
Returns number pieces on specified index |
int |
getPieceX(int index,
int pieceNo,
boolean white)
Returns x coordinate for a piece on specified row-index. |
int |
getPieceY(int index,
int pieceNo,
boolean white)
Returns y coordinate for a piece on specified row-index. |
void |
invalidate()
Invalidates this canvas, forcing a full repaint on next call to paint() |
boolean |
isCursorValid()
Returns whether there is a valid cursor or not. |
boolean |
isUserMovable()
Returns whether the player can move any pieces or not. |
boolean |
isWhite(int index)
Returns true if there are white pieces on specified index, returns false if there are black or no pieces. |
int |
loadCanvas(java.io.DataInputStream dis)
Loads the state of a graphical representation of the board. |
void |
movePiece(boolean white,
int from,
int to,
int piecesOnSrc,
int piecesOnDst)
Called from logic when a piece is moved. |
void |
removePiece(boolean white,
int index)
Removes a piece from the canvas |
void |
requestRepaint()
Requests a repaint of whole canvas. |
int |
saveCanvas(java.io.DataOutputStream dos)
Saves the state of the graphical representation of the board. |
void |
selectTurns(int wDice,
int bDice)
Called from logic on a new game, when players toss one dice each and the one with highest value starts. |
void |
setCurrentLocalPlayer(LocalPlayer player)
Set the local player that will receive interaction calls made on this canvas. |
void |
setDiceValues(int dice1,
int dice2)
Sets the dice values to be drawn and resets consume status |
void |
setDrawDiceValues(boolean enable)
Enables/Disables drawing of dice values. |
void |
setPieces(boolean white,
int index,
int pieces)
Sets number of pieces on specified index |
void |
setQueryCommit(boolean commit)
Called from logic when the user should commit his/her moves or when the user has commited. |
void |
setStartPositions()
Sets up start positions for white and black player |
void |
shutdown()
Shuts down the canvas logic. |
void |
throwDices(boolean white)
Called from logic when dices are thrown on a new turn, starts the dice animation. |
void |
undoConsumedDiceValue(int diceVal)
Called from logic when user has undoed a move based on specified dice value. |
void |
updateCursor()
Updates the cursor. |
void |
updateUndoCommand()
Enables/disables the possibility for user to perform a undo, depending on game state. |
boolean |
waitingForCommit()
Returns whether the canvas is waiting for the user to commit his/her moves. |
Methods inherited from class bluegammon.gui.PopupCanvas |
getPopup, setPopup |
Methods inherited from class javax.microedition.lcdui.Canvas |
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, isDoubleBuffered, repaint, repaint, serviceRepaints, setFullScreenMode |
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 |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface bluegammon.gui.animation.RepaintRequestable |
isShown, repaint |
Field Detail |
public static final float PIECE_Z
public static final javax.microedition.lcdui.Command CMD_UNDO
public static final javax.microedition.lcdui.Command CMD_EXIT
Method Detail |
public void setStartPositions()
public void selectTurns(int wDice, int bDice)
wDice
- value of white dicebDice
- value of black dicepublic void throwDices(boolean white)
white
- the color of dicespublic void movePiece(boolean white, int from, int to, int piecesOnSrc, int piecesOnDst)
white
- Color of piecefrom
- From index.to
- To index.piecesOnSrc
- Number of pieces on source indexpiecesOnDst
- Number of pieces on dest indexpublic void consumeDiceValue(int diceVal)
diceVal
- The dice value usedpublic void undoConsumedDiceValue(int diceVal)
diceVal
- The dice value being undoedpublic void setQueryCommit(boolean commit)
commit
- True if user should commit, false if user has commited.public void finishGame(boolean white, int pieces, int pts)
white
- The color of the winner.pieces
- Pieces left for loser.pts
- Points per piece,public void invalidate()
public void shutdown()
public void setCurrentLocalPlayer(LocalPlayer player)
player
- The local player, or null if current player is not local.public void addPiece(boolean white, int index)
white
- true if white piece, false if blackindex
- where to place the piecepublic void removePiece(boolean white, int index)
white
- true if white piece, false if blackindex
- where from to remove the piecepublic void setPieces(boolean white, int index, int pieces)
white
- true if white piece, false if blackindex
- The board indexpieces
- Number of piecespublic int getPieces(int index)
index
- The board index
public int getPieces(boolean white, int index)
white
- true if white piece, false if blackindex
- The board index
public boolean isWhite(int index)
index
- The board index
public boolean isUserMovable()
public int getCurrentCursorIndex()
public boolean waitingForCommit()
public void updateCursor()
public void updateUndoCommand()
public void allowInteraction(boolean allow)
allow
- enable/disable interaction.public void setDiceValues(int dice1, int dice2)
dice1
- value of dice 1 (0-5)dice2
- value of dice 2 (0-5)public void setDrawDiceValues(boolean enable)
enable
- True when dice values should be drawn,
falsw when dice values should not be drawn.public void commandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)
SoftButtonControl
.
commandAction
in interface javax.microedition.lcdui.CommandListener
c
- the command.d
- the displayable.public void cursorNearestIndex(int oldIndex, int oldTarget)
oldIndex
- old index before changeoldTarget
- old target index before changepublic void cursorSwapSide()
public void cursorNextIndex()
public void cursorBackIndex()
public boolean isCursorValid()
public int getBoardHeight()
public void addWinningPieceAnimation(boolean white, WinnerAnim winAnim)
white
- True to animate white pieces, false for black.winAnim
- The comprising winning animation.public javax.microedition.lcdui.Image getBoardImage()
public int getPieceX(int index, int pieceNo, boolean white)
index
- The row-index.pieceNo
- The piece number on this index.white
- true if white, false if black.
public int getPieceY(int index, int pieceNo, boolean white)
index
- The row-index.pieceNo
- The piece number on this index.white
- true if white, false if black.
public void drawPiece(int x, int y, float angle, boolean horizTilt, float dz, boolean white, javax.microedition.lcdui.Graphics g)
x
- x-coordinate.y
- y-coordinate.angle
- Piece angle.horizTilt
- True for horizontal tilt, false for vertical.dz
- Piece delta z.white
- True for white piece, false for black.g
- Graphics context to draw to.public void drawPiece3D(int x, int y, float angle, boolean horizTilt, float dz, boolean white, Context3D c3d, javax.microedition.m3g.Graphics3D g3d)
x
- x-coordinate.y
- y-coordinate.angle
- Piece angle.horizTilt
- True for horizontal tilt, false for vertical.dz
- Piece delta z.white
- True for white piece, false for black.g3d
- 3D Graphics context to draw to.public void requestRepaint()
requestRepaint
in interface RepaintRequestable
public void commitRepaint()
commitRepaint
in interface RepaintRequestable
public int saveCanvas(java.io.DataOutputStream dos) throws java.io.IOException
dos
- The output stream.
java.io.IOException
- if save failed.public int loadCanvas(java.io.DataInputStream dis) throws java.io.IOException
dis
- The input stream.
java.io.IOException
- if load failed.public static BoardCanvas getInstance()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |