public abstract class

TurnBasedApp

extends Multiplayer
java.lang.Object
   ↳ mobisocial.socialkit.musubi.multiplayer.Multiplayer
     ↳ mobisocial.socialkit.musubi.multiplayer.TurnBasedApp

Class Overview

Manages the state machine associated with a turn-based multiplayer application.

Summary

Constants
int NO_TURN
[Expand]
Inherited Constants
From class mobisocial.socialkit.musubi.multiplayer.Multiplayer
Fields
protected boolean DBG
Public Constructors
TurnBasedApp(Musubi musubi, DbObj objContext)
Public Methods
void disableStateUpdates()
Often called in an activity's onPause method.
void enableStateUpdates()
Often called in an activity's onResume method.
int getGlobalMemberCursor()
Returns a cursor within the membership list that points to the user with control of the state machine.
int getLastTurnNumber()
JSONObject getLatestState()
Returns the latest application state.
int getLocalMemberIndex()
Returns the index within the membership list that represents the local user.
User getLocalUser()
String[] getMembers()
Returns the array of member identifiers.
DbIdentity getUser(int memberIndex)
boolean isMyTurn()
Returns true if the local member index equals the membership cursor.
JSONArray membersJsonArray()
static Obj newInstance(String type, List<DbIdentity> participants, JSONObject initialState)
Prepares a new TurnBasedApp object that can be inserted into a feed.
boolean takeTurn(JSONArray members, int nextPlayer, JSONObject state)
boolean takeTurn(int nextPlayer, JSONObject state)
Updates the state machine with the user's move, passing control to nextPlayer.
boolean takeTurn(JSONObject state)
Updates the state machine with the user's move, passing control to the next player in getMembers().
Protected Methods
abstract FeedRenderable getFeedView(JSONObject state)
Returns a view suitable for display in a feed.
abstract void onStateUpdate(JSONObject json)
Override this method to handle state updates to this turn-basd app.
[Expand]
Inherited Methods
From class mobisocial.socialkit.musubi.multiplayer.Multiplayer
From class java.lang.Object

Constants

protected static final int NO_TURN

Constant Value: -1 (0xffffffff)

Fields

protected boolean DBG

Public Constructors

public TurnBasedApp (Musubi musubi, DbObj objContext)

Public Methods

public void disableStateUpdates ()

Often called in an activity's onPause method.

public void enableStateUpdates ()

Often called in an activity's onResume method.

public int getGlobalMemberCursor ()

Returns a cursor within the membership list that points to the user with control of the state machine.

public int getLastTurnNumber ()

public JSONObject getLatestState ()

Returns the latest application state.

public int getLocalMemberIndex ()

Returns the index within the membership list that represents the local user.

public User getLocalUser ()

public String[] getMembers ()

Returns the array of member identifiers.

public DbIdentity getUser (int memberIndex)

public boolean isMyTurn ()

Returns true if the local member index equals the membership cursor. In other words, its the local user's turn.

public JSONArray membersJsonArray ()

public static Obj newInstance (String type, List<DbIdentity> participants, JSONObject initialState)

Prepares a new TurnBasedApp object that can be inserted into a feed. Once inserted, the object can be used to create a new TurnBasedApp instance via TurnBasedApp#TurnBasedApp(DbObj).

public boolean takeTurn (JSONArray members, int nextPlayer, JSONObject state)

public boolean takeTurn (int nextPlayer, JSONObject state)

Updates the state machine with the user's move, passing control to nextPlayer. The state machine is only updated if it is the local user's turn.

Returns
  • true if a turn was taken.

public boolean takeTurn (JSONObject state)

Updates the state machine with the user's move, passing control to the next player in getMembers(). The state machine is only updated if it is the local user's turn.

Returns
  • true if a turn was taken.

Protected Methods

protected abstract FeedRenderable getFeedView (JSONObject state)

Returns a view suitable for display in a feed.

protected abstract void onStateUpdate (JSONObject json)

Override this method to handle state updates to this turn-basd app.