Cleaned up the code to be more sensible.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2344 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Table.java,v 1.15 2003/03/27 23:25:59 mdb Exp $
|
// $Id: Table.java,v 1.16 2003/03/27 23:45:04 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.data;
|
package com.threerings.parlor.data;
|
||||||
|
|
||||||
@@ -84,10 +84,11 @@ public class Table
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Once a table is ready to play (see {@link #readyToStart}), the
|
* Once a table is ready to play (see {@link #mayBeStarted} and {@link
|
||||||
* players array can be fetched using this method. It will return an
|
* #shouldBeStarted}), the players array can be fetched using this
|
||||||
* array containing the usernames of all of the players in the game,
|
* method. It will return an array containing the usernames of all of
|
||||||
* sized properly and with each player in the appropriate position.
|
* the players in the game, sized properly and with each player in the
|
||||||
|
* appropriate position.
|
||||||
*/
|
*/
|
||||||
public String[] getPlayers ()
|
public String[] getPlayers ()
|
||||||
{
|
{
|
||||||
@@ -189,24 +190,41 @@ public class Table
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this table has occupants in all of the desired
|
* Returns true if this table has a sufficient number of occupants
|
||||||
* positions and should be started.
|
* that the game can be started.
|
||||||
*/
|
*/
|
||||||
public boolean readyToStart ()
|
public boolean mayBeStarted ()
|
||||||
|
{
|
||||||
|
// make sure at least the minimum number of players are here
|
||||||
|
int want = _tconfig.getMinimumPlayers(), have = 0;
|
||||||
|
for (int i = 0; i < occupants.length; i++) {
|
||||||
|
if (!StringUtil.blank(occupants[i])) {
|
||||||
|
if (++have == want) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if sufficient seats are occupied that the game should
|
||||||
|
* be automatically started.
|
||||||
|
*/
|
||||||
|
public boolean shouldBeStarted ()
|
||||||
{
|
{
|
||||||
int need = _tconfig.getDesiredPlayers();
|
int need = _tconfig.getDesiredPlayers();
|
||||||
if (need == -1) {
|
if (need == -1) {
|
||||||
need = _tconfig.getMaximumPlayers();
|
need = _tconfig.getMaximumPlayers();
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < occupants.length; i++) {
|
||||||
// make sure the first "need" players are filled in
|
|
||||||
for (int i = 0; i < need; i++) {
|
|
||||||
if (StringUtil.blank(occupants[i])) {
|
if (StringUtil.blank(occupants[i])) {
|
||||||
return false;
|
if (--need == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TableConfig.java,v 1.2 2001/10/23 20:23:29 mdb Exp $
|
// $Id: TableConfig.java,v 1.3 2003/03/27 23:45:04 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.data;
|
package com.threerings.parlor.data;
|
||||||
|
|
||||||
@@ -21,10 +21,10 @@ public interface TableConfig
|
|||||||
public int getMaximumPlayers ();
|
public int getMaximumPlayers ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of players desired for this game, or -1 if the
|
* Returns the number of players that when reached, will cause the
|
||||||
* table services should allow up to the maximum number of players to
|
* game to automatically be started. If this value is -1 the game will
|
||||||
* join the table, but also allow the game to be started by the table
|
* not automatically be started until the maximum number of players is
|
||||||
* creator any time after the minimum number of players has arrived.
|
* reached.
|
||||||
*/
|
*/
|
||||||
public int getDesiredPlayers ();
|
public int getDesiredPlayers ();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: TableManager.java,v 1.8 2002/10/06 00:53:15 mdb Exp $
|
// $Id: TableManager.java,v 1.9 2003/03/27 23:45:04 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.parlor.server;
|
package com.threerings.parlor.server;
|
||||||
|
|
||||||
@@ -157,8 +157,8 @@ public class TableManager
|
|||||||
throw new InvocationException(error);
|
throw new InvocationException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine whether or not it's time to start the game
|
// if the table is sufficiently full, start the game automatically
|
||||||
if (table.readyToStart()) {
|
if (table.shouldBeStarted()) {
|
||||||
// create the game manager
|
// create the game manager
|
||||||
GameManager gmgr =
|
GameManager gmgr =
|
||||||
createGameManager(table.config, table.getPlayers());
|
createGameManager(table.config, table.getPlayers());
|
||||||
|
|||||||
Reference in New Issue
Block a user