Provide access to player info via safer getter methods rather than giving
away references to our internal arrays. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1495 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: GameManager.java,v 1.35 2002/06/19 23:06:08 shaper Exp $
|
// $Id: GameManager.java,v 1.36 2002/06/19 23:18:58 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.game;
|
package com.threerings.parlor.game;
|
||||||
|
|
||||||
@@ -96,11 +96,27 @@ public class GameManager extends PlaceManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of the usernames of the players in this game.
|
* Returns the name of the player with the specified index.
|
||||||
*/
|
*/
|
||||||
public String[] getPlayers ()
|
public String getPlayerName (int index)
|
||||||
{
|
{
|
||||||
return _players;
|
return _players[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user object oid of the player with the specified index.
|
||||||
|
*/
|
||||||
|
public int getPlayerOid (int index)
|
||||||
|
{
|
||||||
|
return _playerOids[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of players in the game.
|
||||||
|
*/
|
||||||
|
public int getPlayerCount ()
|
||||||
|
{
|
||||||
|
return _players.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TurnGameManager.java,v 1.5 2002/02/12 06:57:30 mdb Exp $
|
// $Id: TurnGameManager.java,v 1.6 2002/06/19 23:18:58 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.turn;
|
package com.threerings.parlor.turn;
|
||||||
|
|
||||||
@@ -32,7 +32,13 @@ public interface TurnGameManager
|
|||||||
* Extending {@link GameManager} should automatically handle
|
* Extending {@link GameManager} should automatically handle
|
||||||
* implementing this method.
|
* implementing this method.
|
||||||
*/
|
*/
|
||||||
public String[] getPlayers ();
|
public String getPlayerName (int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extending {@link GameManager} should automatically handle
|
||||||
|
* implementing this method.
|
||||||
|
*/
|
||||||
|
public int getPlayerCount ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when we are about to start the next turn. Implementations
|
* Called when we are about to start the next turn. Implementations
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TurnGameManagerDelegate.java,v 1.4 2002/02/13 03:21:28 mdb Exp $
|
// $Id: TurnGameManagerDelegate.java,v 1.5 2002/06/19 23:18:58 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.turn;
|
package com.threerings.parlor.turn;
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
public int getTurnHolderIndex ()
|
public int getTurnHolderIndex ()
|
||||||
{
|
{
|
||||||
String holder = _turnGame.getTurnHolder();
|
String holder = _turnGame.getTurnHolder();
|
||||||
for (int i = 0; i < _players.length; i++) {
|
for (int i = 0; i < _tgmgr.getPlayerCount(); i++) {
|
||||||
if (_players[i].equals(holder)) {
|
if (_tgmgr.getPlayerName(i).equals(holder)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
public void startTurn ()
|
public void startTurn ()
|
||||||
{
|
{
|
||||||
// sanity check
|
// sanity check
|
||||||
if (_turnIdx < 0 || _turnIdx >= _players.length) {
|
if (_turnIdx < 0 || _turnIdx >= _tgmgr.getPlayerCount()) {
|
||||||
Log.warning("startTurn() called with invalid turn index " +
|
Log.warning("startTurn() called with invalid turn index " +
|
||||||
"[turnIdx=" + _turnIdx + "].");
|
"[turnIdx=" + _turnIdx + "].");
|
||||||
// abort, abort
|
// abort, abort
|
||||||
@@ -73,7 +73,7 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
_tgmgr.turnWillStart();
|
_tgmgr.turnWillStart();
|
||||||
|
|
||||||
// and set the turn indicator accordingly
|
// and set the turn indicator accordingly
|
||||||
_turnGame.setTurnHolder(_players[_turnIdx]);
|
_turnGame.setTurnHolder(_tgmgr.getPlayerName(_turnIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,9 +117,6 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
*/
|
*/
|
||||||
public void gameDidStart ()
|
public void gameDidStart ()
|
||||||
{
|
{
|
||||||
// grab the players array
|
|
||||||
_players = _tgmgr.getPlayers();
|
|
||||||
|
|
||||||
// figure out who will be first
|
// figure out who will be first
|
||||||
setFirstTurnHolder();
|
setFirstTurnHolder();
|
||||||
|
|
||||||
@@ -137,7 +134,7 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
{
|
{
|
||||||
// TODO: sort out a better random number generator and make it
|
// TODO: sort out a better random number generator and make it
|
||||||
// available via the parlor services
|
// available via the parlor services
|
||||||
_turnIdx = MathUtil.random(_players.length);
|
_turnIdx = MathUtil.random(_tgmgr.getPlayerCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,7 +147,7 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
protected void setNextTurnHolder ()
|
protected void setNextTurnHolder ()
|
||||||
{
|
{
|
||||||
// next!
|
// next!
|
||||||
_turnIdx = (_turnIdx + 1) % _players.length;
|
_turnIdx = (_turnIdx + 1) % _tgmgr.getPlayerCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The game manager for which we are delegating. */
|
/** The game manager for which we are delegating. */
|
||||||
@@ -159,10 +156,6 @@ public class TurnGameManagerDelegate extends GameManagerDelegate
|
|||||||
/** A reference to our game object. */
|
/** A reference to our game object. */
|
||||||
protected TurnGameObject _turnGame;
|
protected TurnGameObject _turnGame;
|
||||||
|
|
||||||
/** Our own happy copy of the game manager's players array. I *love*
|
|
||||||
* not having fucking multiple inheritance. */
|
|
||||||
protected String[] _players;
|
|
||||||
|
|
||||||
/** The offset into the _players array of the current turn holder or
|
/** The offset into the _players array of the current turn holder or
|
||||||
* -1 if it's no one's turn. */
|
* -1 if it's no one's turn. */
|
||||||
protected int _turnIdx = -1;
|
protected int _turnIdx = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user