|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectMIDlet
client.framework.models.AbstractGame
public abstract class AbstractGame
This class is the main model for the framework. It contains the state
information for the game, and is responsible for displaying the correct
displayable element at all times.
In addition, this class is responsible for communicating using a
Communicator
, object as well as handling the actions received
from the Communicator
.
This class is the framework's implementation of MIDlet, and
contains the startApp
method, which is a J2ME
application's main method.
Finally, this class contains the two threads responsible for the running
of a game in the framework.
Field Summary | |
---|---|
protected Communicator |
communicator
|
protected GameView |
game
|
protected LobbyView |
lobby
|
static boolean |
MOVEMENT_PREDICTION
|
protected MessageParser |
parser
|
protected AbstractPlayer |
self
|
static java.lang.String |
SEP_ACTION
|
static int[][] |
TEAMCOLORS
|
Constructor Summary | |
---|---|
AbstractGame()
|
Method Summary | |
---|---|
void |
addPlayer(AbstractPlayer player)
Adds a player to the player list. |
void |
addSetting(java.lang.String setting,
java.lang.Object value)
Adds a setting to the game. |
protected abstract GameView |
createGameView()
Creates a game view of the implementing game's specified type, and returns this. |
protected void |
destroyApp(boolean unconditional)
Called when the MIDlet is closed. |
void |
fireChangeSettingsSelected()
Method called when the user selects "Change settings" in the game lobby. |
void |
fireHitTrap()
Method called when the local player scores. |
void |
fireMessagesChanged(java.lang.String message,
boolean append)
Method fired when the list of messages is updated. |
void |
firePlayerListChanged()
Called when the contents of the player list have changed, e.g. because of changed score or added or removed players. |
void |
firePlayerReady(AbstractPlayer player,
java.lang.String value)
Method called when one of the players has signalled that he is ready or not ready. |
void |
fireReadySelected()
Method called when the user selects "Ready" in the game lobby. |
void |
fireReturnToGameSelected()
Called when the player wishes to rejoin the running game after having visited the lobby view. |
void |
fireSelfMoved(int[] movement)
Method called when the local player has moved on the game board. |
void |
fireSessionSelected(int selectedSession)
Called when a player has selected to join a session. |
void |
fireSettingsUpdated(java.util.Hashtable settings)
Method called after returning from the "Change Settings" screen. |
void |
flashAndVibrate()
Method called to make the phone flash and vibrate. |
abstract java.lang.String |
getGameName()
Returns the name of the game. |
int |
getNumberOfPlayers()
Returns the number of players participating in the game. |
MessageParser |
getParser()
Returns the model's MessageParser implementation. |
protected AbstractPlayer |
getPlayer(java.lang.Object id)
Returns the player with the specified id. |
java.util.Hashtable |
getPlayerlist()
Returns a list containing the players currently connected to the game. |
AbstractPlayer |
getSelf()
Returns the local player representation. |
java.util.Vector |
getSessions()
Returns a list of the found sessions. |
java.util.Hashtable |
getSettings()
Returns the list of active settings, where each setting is of the form |
Displayable |
getView()
Returns the currently displayed view. |
protected abstract boolean |
handleSpecialSettings(boolean init)
Checks whether the state of the game is valid according to the game settings. |
boolean |
isTeamsEnabled()
Checks whether the teams are enabled or not. |
void |
loadGame(java.lang.String[] values)
Method called when one of the players have initiated the game. |
abstract AbstractPlayer |
newPlayer(java.lang.String address,
java.lang.String name)
Returns a new player object of the type used in the game, which is a subclass of AbstractPlayer. |
void |
notifyAboutMessageReceived(java.lang.String textMessage)
Method that is called whenever the application receives a text message from one of the other participants. |
protected abstract void |
notifyAboutSpecialActionReceived(AbstractPlayer player,
java.lang.String action,
java.lang.String[][] values)
Method used to parse and interpret messages received from other participants, that are not among the default actions defined in AbstractGame . |
protected void |
pauseApp()
Called when the MIDlet enters its paused state, which can happen for example if the MIDlet is minimized. |
void |
quit()
Called when closing the application. |
void |
refreshSessionList()
Called when the player wishes to refresh the session list. |
void |
removePlayer(AbstractPlayer player)
Removes one of the game participants from the list of players, and from the game board if a game is running |
void |
sendPlayerInfo()
Sends the local player's data to the server. |
void |
setView(Displayable view)
Changes the view currently displayed to the one specified. |
void |
showAlert(java.lang.String title,
java.lang.String message,
int duration_secs,
Displayable nextScreen)
Shows a message for a given amount of time, before changing to another screen. |
protected void |
startApp()
Starts the MIDlet. |
void |
startFramework(java.lang.String name,
java.lang.String[] addresses,
int packetSize)
Called after the player has specified a name. |
void |
startGame()
Called when the player selects "start game" in the lobby menu. |
void |
stopGame(java.lang.String reason)
Ends the game and returns to the lobby. |
void |
viewLobby()
Method called to set the lobby view as the active view. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final boolean MOVEMENT_PREDICTION
public static final java.lang.String SEP_ACTION
public static final int[][] TEAMCOLORS
protected MessageParser parser
protected Communicator communicator
protected AbstractPlayer self
protected LobbyView lobby
protected GameView game
Constructor Detail |
---|
public AbstractGame()
Method Detail |
---|
public void startFramework(java.lang.String name, java.lang.String[] addresses, int packetSize)
name
- The name of the local player.addresses
- The address(es) of the server(s) to connect topacketSize
- The maximum packet size (when using UDP)protected abstract GameView createGameView()
public MessageParser getParser()
MessageParser
implementation.
MessageParser
interface.public java.util.Hashtable getPlayerlist()
public java.util.Hashtable getSettings()
public void addSetting(java.lang.String setting, java.lang.Object value)
setting
- The name of the new setting.value
- The value of the new setting.public AbstractPlayer getSelf()
public void addPlayer(AbstractPlayer player)
player
- The new player.public void removePlayer(AbstractPlayer player)
player
- The player to remove.public int getNumberOfPlayers()
public void showAlert(java.lang.String title, java.lang.String message, int duration_secs, Displayable nextScreen)
title
- The title of the message to display.message
- The message to display.duration_secs
- How long the message is displayed.nextScreen
- The screen to display after the message has been shown.public void setView(Displayable view)
view
- The view to display.public Displayable getView()
public void fireMessagesChanged(java.lang.String message, boolean append)
message
- The message to display.append
- Whether the message should append or overwrite previous messagespublic void fireReadySelected()
public void fireChangeSettingsSelected()
SettingsWindow
public void fireSettingsUpdated(java.util.Hashtable settings)
settings
- The values of the settings.public void viewLobby()
public void flashAndVibrate()
public void fireHitTrap()
public void firePlayerReady(AbstractPlayer player, java.lang.String value)
player
- The player sending the signal.value
- "true" if the player is ready, "false" if not.public void startGame()
public void loadGame(java.lang.String[] values)
values
- The screen resolution for this particular game.@param value The game screen resolution
public void fireSelfMoved(int[] movement)
movement
- How much the local player has moved.public void notifyAboutMessageReceived(java.lang.String textMessage)
textMessage
- A string representing the message.Action
public void stopGame(java.lang.String reason)
reason
- The reason for ending the game.public void firePlayerListChanged()
public abstract java.lang.String getGameName()
public abstract AbstractPlayer newPlayer(java.lang.String address, java.lang.String name)
AbstractPlayer
.
address
- The player's network address.name
- The name of the player.
AbstractPlayer.AbstractPlayer(String, String, int, int)
protected abstract boolean handleSpecialSettings(boolean init)
init
- Whether the method is called on game initialisation or not
handleSettings(boolean)
protected abstract void notifyAboutSpecialActionReceived(AbstractPlayer player, java.lang.String action, java.lang.String[][] values)
AbstractGame
.
For a message, the sender (AbstractPlayer
) is specified, and a
three-letter word identifying the action leading to the message. The final
parameter is a String containing one or more values corresponding to the action.
player
- The sender of the messageaction
- The action specified in the messagevalues
- The value(s) contained in the messageprotected void startApp() throws MIDletStateChangeException
MIDletStateChangeException
protected void pauseApp()
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
unconditional
- If true when this method is called, the MIDlet
must cleanup and release all resources.
MIDletStateChangeException
protected AbstractPlayer getPlayer(java.lang.Object id)
id
- The id of the player.
public void sendPlayerInfo()
AbstractPlayer.getAttributeValues()
public void quit()
destroyApp(boolean)
public java.util.Vector getSessions()
public void fireSessionSelected(int selectedSession)
selectedSession
- The session the player wishes to join.public void refreshSessionList()
public boolean isTeamsEnabled()
public void fireReturnToGameSelected()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |