Added support for minimumPlayerCount, allowing tables to be started

before they're full.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3597 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2005-06-13 23:47:48 +00:00
parent 8bec395301
commit 97b1085388
3 changed files with 41 additions and 49 deletions
@@ -66,6 +66,8 @@ public class DefaultSwingTableConfigurator extends TableConfigurator
public DefaultSwingTableConfigurator (int minPlayers, public DefaultSwingTableConfigurator (int minPlayers,
int desiredPlayers, int maxPlayers, boolean allowPrivate) int desiredPlayers, int maxPlayers, boolean allowPrivate)
{ {
_config.minimumPlayerCount = minPlayers;
// create a slider for players, if applicable // create a slider for players, if applicable
if (minPlayers != maxPlayers) { if (minPlayers != maxPlayers) {
_playerSlider = new SimpleSlider( _playerSlider = new SimpleSlider(
+35 -49
View File
@@ -63,12 +63,11 @@ public class Table
/** /**
* Creates a new table instance, and assigns it the next monotonically * Creates a new table instance, and assigns it the next monotonically
* increasing table id. The supplied config instance must implement * increasing table id.
* {@link TableConfig} or a <code>ClassCastException</code> will be
* thrown.
* *
* @param lobbyOid the object id of the lobby in which this table is * @param lobbyOid the object id of the lobby in which this table is
* to live. * to live.
* @param tconfig the table configuration for this table.
* @param config the configuration of the game being matchmade by this * @param config the configuration of the game being matchmade by this
* table. * table.
*/ */
@@ -113,6 +112,33 @@ public class Table
return tableId.intValue(); return tableId.intValue();
} }
/**
* Returns true if there is no one sitting at this table.
*/
public boolean isEmpty ()
{
for (int i = 0; i < bodyOids.length; i++) {
if (bodyOids[i] != 0) {
return false;
}
}
return true;
}
/**
* Count the number of players currently occupying this table.
*/
public int getOccupiedCount ()
{
int count = 0;
for (int ii = 0; ii < occupants.length; ii++) {
if (occupants[ii] != null) {
count++;
}
}
return count;
}
/** /**
* Once a table is ready to play (see {@link #mayBeStarted} and {@link * Once a table is ready to play (see {@link #mayBeStarted} and {@link
* #shouldBeStarted}), the players array can be fetched using this * #shouldBeStarted}), the players array can be fetched using this
@@ -126,20 +152,11 @@ public class Table
return null; return null;
} }
// count up the players
int pcount = 0;
for (int i = 0; i < occupants.length; i++) {
if (occupants[i] != null) {
pcount++;
}
}
// create and populate the players array // create and populate the players array
Name[] players = new Name[pcount]; Name[] players = new Name[getOccupiedCount()];
pcount = 0; for (int ii = 0, dex = 0; ii < occupants.length; ii++) {
for (int i = 0; i < occupants.length; i++) { if (occupants[ii] != null) {
if (occupants[i] != null) { players[dex++] = occupants[ii];
players[pcount++] = occupants[i];
} }
} }
@@ -230,19 +247,7 @@ public class Table
*/ */
public boolean mayBeStarted () public boolean mayBeStarted ()
{ {
// TODO: this becomes more meaningful if we implement games return tconfig.minimumPlayerCount <= getOccupiedCount();
// that can optionally be started with less than the desired number
// make sure at least the minimum number of players are here
int want = tconfig.desiredPlayerCount, have = 0;
for (int i = 0; i < occupants.length; i++) {
if (occupants[i] != null) {
if (++have == want) {
return true;
}
}
}
return false;
} }
/** /**
@@ -251,26 +256,7 @@ public class Table
*/ */
public boolean shouldBeStarted () public boolean shouldBeStarted ()
{ {
int need = tconfig.desiredPlayerCount; return tconfig.desiredPlayerCount <= getOccupiedCount();
for (int i = 0; i < occupants.length; i++) {
if (occupants[i] != null && --need == 0) {
return true;
}
}
return false;
}
/**
* Returns true if there is no one sitting at this table.
*/
public boolean isEmpty ()
{
for (int i = 0; i < bodyOids.length; i++) {
if (bodyOids[i] != 0) {
return false;
}
}
return true;
} }
/** /**
@@ -33,6 +33,10 @@ public class TableConfig extends SimpleStreamableObject
* party game. */ * party game. */
public int desiredPlayerCount; public int desiredPlayerCount;
/** The minimum number of players needed for the game to start at
* the creator's discretion. */
public int minimumPlayerCount;
/** Whether the table is "private". */ /** Whether the table is "private". */
public boolean privateTable; public boolean privateTable;
} }