|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbluegammon.Bluegammon
The Bluegammon
class represents the Bluegammon MIDlet
game altogether. It coordinates the macro state of the application.
This class collects common functionality as starting and stopping a backgammon game, showing a popup, or getting string input from user. It is invoked statically since it mainly is a mediator.
Field Summary | |
static int |
AUDIO_OFF
Key for audio off (boolean) |
static int |
BLACK_PREFERRED
Key for preferred color (boolean) |
static int |
DEVICE_ID
Key for device id (int) |
static int |
GAME_TYPE_LOCAL
Represents a game that is only played on this device |
static int |
GAME_TYPE_REMOTE_CLIENT
Represents a distributed game where this device acts client |
static int |
GAME_TYPE_REMOTE_SERVER
Represents a distributed game where this device acts server |
static int |
GAMEREC_GAME_COUNT
First key in gamerecords, number of games against this opponent (int) |
static int |
GAMEREC_MY_SCORE
First key in gamerecords, player score (int) |
static int |
GAMEREC_OP_ID
First key in gamerecords, device ids (int) |
static int |
GAMEREC_OP_NAME
First key in gamerecords, opponent name (char[]) |
static int |
GAMEREC_OP_SCORE
First key in gamerecords, opponent score (int) |
static int |
GAMEREC_SAVED_GAME_DATA
First key in gamerecords, saved game data (byte[]) |
static int |
GAMEREC_TIMESTAMP
First key in gamerecords, timestamp (long) |
static int |
GAMERECORDS_SIZE
Max number of opponent scores that can be persistent |
static int |
HAS_SAVED_LOCAL_GAME
Key for saved game boolean flag (boolean) |
static int |
PLAYER_NAME
Key for player name (char[]) |
static int |
RULES_PREFERRED
Key for preferred rules (int) |
static int |
SAVED_GAME_DATA
Key for saved game data (byte[]) |
static int |
VIBRA_OFF
Key for vibration off (boolean) |
Method Summary | |
void |
commandAction(javax.microedition.lcdui.Command c,
javax.microedition.lcdui.Displayable d)
|
static void |
exitGame()
Exits a game. |
static PopupCanvas |
getCanvas()
Returns current canvas |
static Popup |
getCurrentPopup()
Returns current displayed popup |
static int |
getGameType()
Returns current game type, one of GAME_TYPE_LOCAL ,
GAME_TYPE_REMOTE_SERVER , GAME_TYPE_REMOTE_CLIENT . |
static void |
getStringInput(java.lang.String title,
char[] defaultText,
int length,
int constraints,
StringInputHandler ih)
Gets input from the user. |
static boolean |
hasSavedLocalGame()
Returns true if there exists a saved phone game |
static void |
init(BluegammonMIDlet bg,
javax.microedition.lcdui.Display display)
Initializes this class. |
static boolean |
isShowingPopup()
Returns true if a popup is currently displayed to the user |
static void |
resumeSavedLocalGame()
Resumes a saved game |
void |
selectedChoice(byte choice,
boolean timeOut)
Called when an selection has been made. |
static void |
setBackgammonConnection(BackgammonConnection conn)
Sets the connection used in remote game. |
static void |
setCanvas(PopupCanvas c)
Sets specified canvas as current |
static Popup |
showPopup(char[] text,
char[][] altTexts,
int timeOutInSeconds,
int defaultChoice,
int timeOutChoice,
PopupListener listener)
Shows a popup on the device display, enabling the user to make a choice amongst specified alternatives. |
static void |
showRules()
Displays a popup with current rule settings. |
static void |
shutdown()
Shuts down the MIDlet. |
static void |
startLocalGame()
Start a new game for two players on one phone. |
static void |
startRemoteGame(boolean server,
char[] localName)
Starts a remote game, either as server or as client. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEVICE_ID
public static final int PLAYER_NAME
public static final int HAS_SAVED_LOCAL_GAME
public static final int SAVED_GAME_DATA
public static final int BLACK_PREFERRED
public static final int AUDIO_OFF
public static final int VIBRA_OFF
public static final int RULES_PREFERRED
public static final int GAMERECORDS_SIZE
public static final int GAMEREC_OP_ID
public static final int GAMEREC_OP_NAME
public static final int GAMEREC_MY_SCORE
public static final int GAMEREC_OP_SCORE
public static final int GAMEREC_GAME_COUNT
public static final int GAMEREC_TIMESTAMP
public static final int GAMEREC_SAVED_GAME_DATA
public static int GAME_TYPE_LOCAL
public static int GAME_TYPE_REMOTE_SERVER
public static int GAME_TYPE_REMOTE_CLIENT
Method Detail |
public static int getGameType()
GAME_TYPE_LOCAL
,
GAME_TYPE_REMOTE_SERVER
, GAME_TYPE_REMOTE_CLIENT
.
public static void setBackgammonConnection(BackgammonConnection conn)
startRemoteGame
conn
- The connection used with remote player.public static boolean hasSavedLocalGame()
public static void startLocalGame()
public static void startRemoteGame(boolean server, char[] localName)
setBackgammonConnection
. It handshakes
with the other device and starts a new game, or resumes a game if any of the
devices has a saved game. On conflicting preferred settings (color and rules)
the server wins.
server
- True if server, false if client.localName
- The name of this player.setBackgammonConnection(BackgammonConnection)
public static void resumeSavedLocalGame()
public static void exitGame()
public static void shutdown()
public static void showRules()
public static void getStringInput(java.lang.String title, char[] defaultText, int length, int constraints, StringInputHandler ih)
InputHandler
.
title
- The title of the input dialog.defaultText
- The default text presented in the input dialog.length
- The maximum length of the input.constraints
- The constraints of the text as defined in TextField
.ih
- The input handler, which handles the input when the user
commits the text.public static void setCanvas(PopupCanvas c)
c
- The canvas to setpublic static PopupCanvas getCanvas()
public static boolean isShowingPopup()
public static Popup getCurrentPopup()
public static Popup showPopup(char[] text, char[][] altTexts, int timeOutInSeconds, int defaultChoice, int timeOutChoice, PopupListener listener)
Bluegammon.getCurrentPopup()
or
Bluegammon..isShowingPopup()
text
- Character array with text presented in popup.altTexts
- Array of character arrays with alternatives presented in popup. If
this argument is null, no alternatives are presented.timeOutInSeconds
- The timeout in seconds. If this argument is set to zero,
the popup is displayed until the a user makes a choice. If no
choices are given and the timeout is zero, this popup will not show.defaultChoice
- The default selection when the popup appears.timeOutChoice
- The choice reported if the popup times out or is overridden by
another popup.listener
- The listener to this popup.public static void init(BluegammonMIDlet bg, javax.microedition.lcdui.Display display)
bg
- The bluegammon midlet.display
- The display.public void selectedChoice(byte choice, boolean timeOut)
PopupListener
selectedChoice
in interface PopupListener
choice
- The index of the alternatives that were chosen.timeOut
- True if the choice was made because of a time out.public void commandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)
commandAction
in interface javax.microedition.lcdui.CommandListener
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |