Remove trailing whitespace throughout, and then widen/vararg/foreachize some
card game stuff that we were looking at. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@804 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -34,8 +34,7 @@ import com.threerings.parlor.turn.client.TurnGameController;
|
||||
import static com.threerings.parlor.card.Log.log;
|
||||
|
||||
/**
|
||||
* A controller class for card games. Handles common functions like
|
||||
* accepting dealt hands.
|
||||
* A controller class for card games. Handles common functions like accepting dealt hands.
|
||||
*/
|
||||
public abstract class CardGameController extends GameController
|
||||
implements TurnGameController, CardCodes, CardGameReceiver
|
||||
@@ -50,8 +49,7 @@ public abstract class CardGameController extends GameController
|
||||
Thread.dumpStack();
|
||||
}
|
||||
|
||||
_ctx.getClient().getInvocationDirector().registerReceiver(
|
||||
new CardGameDecoder(this));
|
||||
_ctx.getClient().getInvocationDirector().registerReceiver(new CardGameDecoder(this));
|
||||
|
||||
super.willEnterPlace(plobj);
|
||||
}
|
||||
@@ -61,8 +59,7 @@ public abstract class CardGameController extends GameController
|
||||
{
|
||||
super.didLeavePlace(plobj);
|
||||
|
||||
_ctx.getClient().getInvocationDirector().unregisterReceiver(
|
||||
CardGameDecoder.RECEIVER_CODE);
|
||||
_ctx.getClient().getInvocationDirector().unregisterReceiver(CardGameDecoder.RECEIVER_CODE);
|
||||
}
|
||||
|
||||
// Documentation inherited.
|
||||
@@ -80,8 +77,8 @@ public abstract class CardGameController extends GameController
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server deals the client a new hand of cards. Default
|
||||
* implementation does nothing.
|
||||
* Called when the server deals the client a new hand of cards. Default implementation does
|
||||
* nothing.
|
||||
*
|
||||
* @param hand the hand dealt to the user
|
||||
*/
|
||||
@@ -89,8 +86,8 @@ public abstract class CardGameController extends GameController
|
||||
{}
|
||||
|
||||
/**
|
||||
* Dispatched to the client when it has received a set of cards
|
||||
* from another player. Default implementation does nothing.
|
||||
* Dispatched to the client when it has received a set of cards from another player. Default
|
||||
* implementation does nothing.
|
||||
*
|
||||
* @param plidx the index of the player providing the cards
|
||||
* @param cards the cards received
|
||||
@@ -99,9 +96,8 @@ public abstract class CardGameController extends GameController
|
||||
{}
|
||||
|
||||
/**
|
||||
* Dispatched to the client when the server has forced it to send
|
||||
* a set of cards to another player. Default implementation does
|
||||
* nothing.
|
||||
* Dispatched to the client when the server has forced it to send a set of cards to another
|
||||
* player. Default implementation does nothing.
|
||||
*
|
||||
* @param plidx the index of the player to which the cards were sent
|
||||
* @param cards the cards sent
|
||||
@@ -110,8 +106,8 @@ public abstract class CardGameController extends GameController
|
||||
{}
|
||||
|
||||
/**
|
||||
* Dispatched to the client when a set of cards is transferred between
|
||||
* two other players in the game. Default implementation does nothing.
|
||||
* Dispatched to the client when a set of cards is transferred between two other players in
|
||||
* the game. Default implementation does nothing.
|
||||
*
|
||||
* @param fromidx the index of the player sending the cards
|
||||
* @param toidx the index of the player receiving the cards
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface CardGameReceiver extends InvocationReceiver
|
||||
* @param hand the received hand
|
||||
*/
|
||||
public void receivedHand (int oid, Hand hand);
|
||||
|
||||
|
||||
/**
|
||||
* Dispatched to the client when it has received a set of cards
|
||||
* from another player.
|
||||
@@ -48,7 +48,7 @@ public interface CardGameReceiver extends InvocationReceiver
|
||||
* @param cards the cards received
|
||||
*/
|
||||
public void receivedCardsFromPlayer (int plidx, Card[] cards);
|
||||
|
||||
|
||||
/**
|
||||
* Dispatched to the client when the server has forced it to send
|
||||
* a set of cards to another player.
|
||||
@@ -57,7 +57,7 @@ public interface CardGameReceiver extends InvocationReceiver
|
||||
* @param cards the cards sent
|
||||
*/
|
||||
public void sentCardsToPlayer (int plidx, Card[] cards);
|
||||
|
||||
|
||||
/**
|
||||
* Dispatched to the client when a set of cards is transferred between
|
||||
* two other players in the game.
|
||||
|
||||
@@ -35,7 +35,7 @@ public interface CardSpriteObserver
|
||||
* @param me the mouse event associated with the drag
|
||||
*/
|
||||
public void cardSpriteClicked (CardSprite sprite, MouseEvent me);
|
||||
|
||||
|
||||
/**
|
||||
* Notifies the observer that the user moved the mouse pointer onto
|
||||
* a card sprite.
|
||||
@@ -44,7 +44,7 @@ public interface CardSpriteObserver
|
||||
* @param me the mouse event associated with the entrance
|
||||
*/
|
||||
public void cardSpriteEntered (CardSprite sprite, MouseEvent me);
|
||||
|
||||
|
||||
/**
|
||||
* Notifies the observer that the user moved the mouse pointer off of
|
||||
* a card sprite.
|
||||
@@ -53,7 +53,7 @@ public interface CardSpriteObserver
|
||||
* @param me the mouse event associated with the exit
|
||||
*/
|
||||
public void cardSpriteExited (CardSprite sprite, MouseEvent me);
|
||||
|
||||
|
||||
/**
|
||||
* Notifies the observer that the user dragged a card sprite to a new
|
||||
* location.
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
*/
|
||||
public Card ()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new card.
|
||||
*
|
||||
@@ -46,10 +46,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
{
|
||||
_value = (byte)((suit << 5) | number);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of the card, either from 2 to 11 or
|
||||
* KING, QUEEN, JACK, ACE, RED_JOKER, or BLACK_JOKER.
|
||||
* Returns the value of the card, either from 2 to 11 or KING, QUEEN, JACK, ACE, RED_JOKER, or
|
||||
* BLACK_JOKER.
|
||||
*
|
||||
* @return the value of the card
|
||||
*/
|
||||
@@ -57,10 +57,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
{
|
||||
return (_value & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the suit of the card: SPADES, HEARTS, DIAMONDS, or
|
||||
* CLUBS. If the card is the joker, the suit is undefined.
|
||||
* Returns the suit of the card: SPADES, HEARTS, DIAMONDS, or CLUBS. If the card is the joker,
|
||||
* the suit is undefined.
|
||||
*
|
||||
* @return the suit of the card
|
||||
*/
|
||||
@@ -68,7 +68,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
{
|
||||
return (_value >> 5);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the card is a number card (2 to 10).
|
||||
*
|
||||
@@ -77,10 +77,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
public boolean isNumber ()
|
||||
{
|
||||
int number = getNumber();
|
||||
|
||||
|
||||
return number >= 2 && number <= 10;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the card is a face card (KING, QUEEN, or JACK).
|
||||
*
|
||||
@@ -89,10 +89,10 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
public boolean isFace ()
|
||||
{
|
||||
int number = getNumber();
|
||||
|
||||
|
||||
return number == KING || number == QUEEN || number == JACK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the card is an ace.
|
||||
*
|
||||
@@ -102,7 +102,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
{
|
||||
return getNumber() == ACE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the card is a joker.
|
||||
*
|
||||
@@ -111,41 +111,41 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
public boolean isJoker ()
|
||||
{
|
||||
int number = getNumber();
|
||||
|
||||
|
||||
return number == RED_JOKER || number == BLACK_JOKER;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether or not this card is valid. The no-arg public
|
||||
* constructor for deserialization creates an invalid card.
|
||||
* Checks whether or not this card is valid. The no-arg public constructor for deserialization
|
||||
* creates an invalid card.
|
||||
*
|
||||
* @return true if this card is valid, false if not
|
||||
*/
|
||||
public boolean isValid ()
|
||||
{
|
||||
int number = getNumber(), suit = getSuit();
|
||||
|
||||
|
||||
return number == RED_JOKER || number == BLACK_JOKER ||
|
||||
(number >= 2 && number <= ACE &&
|
||||
suit >= SPADES && suit <= DIAMONDS);
|
||||
}
|
||||
|
||||
|
||||
// Documentation inherited.
|
||||
public Comparable<?> getKey ()
|
||||
{
|
||||
if (_key == null) {
|
||||
_key = Byte.valueOf(_value);
|
||||
}
|
||||
|
||||
|
||||
return _key;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode ()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals (Object other)
|
||||
{
|
||||
@@ -156,21 +156,20 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compares this card to another. The card order is the same as the
|
||||
* initial deck ordering: two through ten, jack, queen, king, ace for
|
||||
* spades, hearts, clubs, and diamonds, then the red joker and the
|
||||
* black joker.
|
||||
* Compares this card to another. The card order is the same as the initial deck ordering: two
|
||||
* through ten, jack, queen, king, ace for spades, hearts, clubs, and diamonds, then the red
|
||||
* joker and the black joker.
|
||||
*
|
||||
* @param other the other card to compare this to
|
||||
* @return -1, 0, or +1, depending on whether this card is less than,
|
||||
* equal to, or greater than the other card
|
||||
* @return -1, 0, or +1, depending on whether this card is less than, equal to, or greater
|
||||
* than the other card
|
||||
*/
|
||||
public int compareTo (Card other)
|
||||
{
|
||||
int otherValue = other._value;
|
||||
|
||||
|
||||
if (_value > otherValue) {
|
||||
return +1;
|
||||
} else if(_value < otherValue) {
|
||||
@@ -179,12 +178,12 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
int number = getNumber();
|
||||
|
||||
|
||||
if (number == RED_JOKER) {
|
||||
return "RJ";
|
||||
}
|
||||
@@ -193,7 +192,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
}
|
||||
else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
||||
if (number >= 2 && number <= 9) {
|
||||
sb.append(Integer.toString(number));
|
||||
}
|
||||
@@ -207,7 +206,7 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
default: sb.append('?'); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (getSuit()) {
|
||||
case SPADES: sb.append('s'); break;
|
||||
case HEARTS: sb.append('h'); break;
|
||||
@@ -215,14 +214,14 @@ public class Card implements DSet.Entry, Comparable<Card>, CardCodes
|
||||
case DIAMONDS: sb.append('d'); break;
|
||||
default: sb.append('?'); break;
|
||||
}
|
||||
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** The number of the card. */
|
||||
protected byte _value;
|
||||
|
||||
|
||||
/** The comparison key. */
|
||||
@ActionScript(omit=true)
|
||||
protected transient Byte _key;
|
||||
|
||||
@@ -30,31 +30,31 @@ public interface CardCodes extends InvocationCodes
|
||||
{
|
||||
/** The suit of spades. */
|
||||
public static final int SPADES = 0;
|
||||
|
||||
|
||||
/** The suit of hearts. */
|
||||
public static final int HEARTS = 1;
|
||||
|
||||
|
||||
/** The suit of clubs. */
|
||||
public static final int CLUBS = 2;
|
||||
|
||||
|
||||
/** The suit of diamonds. */
|
||||
public static final int DIAMONDS = 3;
|
||||
|
||||
|
||||
/** The number of the jack. */
|
||||
public static final int JACK = 11;
|
||||
|
||||
|
||||
/** The number of the queen. */
|
||||
public static final int QUEEN = 12;
|
||||
|
||||
|
||||
/** The number of the king. */
|
||||
public static final int KING = 13;
|
||||
|
||||
|
||||
/** The number of the ace. */
|
||||
public static final int ACE = 14;
|
||||
|
||||
|
||||
/** The number of the red joker. */
|
||||
public static final int RED_JOKER = 15;
|
||||
|
||||
|
||||
/** The number of the black joker. */
|
||||
public static final int BLACK_JOKER = 16;
|
||||
}
|
||||
|
||||
@@ -30,16 +30,16 @@ public class PlayerCard implements Streamable
|
||||
{
|
||||
/** The index of the player. */
|
||||
public int pidx;
|
||||
|
||||
|
||||
/** The card that the player played. */
|
||||
public Card card;
|
||||
|
||||
|
||||
/**
|
||||
* No-argument constructor for deserialization.
|
||||
*/
|
||||
public PlayerCard ()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new player card.
|
||||
*
|
||||
|
||||
@@ -36,8 +36,8 @@ import com.threerings.parlor.game.server.GameManager;
|
||||
import com.threerings.parlor.turn.server.TurnGameManager;
|
||||
|
||||
/**
|
||||
* A manager class for card games. Handles common functions like dealing
|
||||
* hands of cards to all players.
|
||||
* A manager class for card games. Handles common functions like dealing hands of cards to all
|
||||
* players.
|
||||
*/
|
||||
public class CardGameManager extends GameManager
|
||||
implements TurnGameManager, CardCodes
|
||||
@@ -48,15 +48,15 @@ public class CardGameManager extends GameManager
|
||||
super.didStartup();
|
||||
_cardgameobj = (CardGameObject)_gameobj;
|
||||
}
|
||||
|
||||
|
||||
// Documentation inherited.
|
||||
public void turnWillStart ()
|
||||
{}
|
||||
|
||||
|
||||
// Documentation inherited.
|
||||
public void turnDidStart ()
|
||||
{}
|
||||
|
||||
|
||||
// Documentation inherited.
|
||||
public void turnDidEnd ()
|
||||
{}
|
||||
@@ -72,9 +72,8 @@ public class CardGameManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be called to start a rematched game. It just starts the
|
||||
* current game anew, but provides a mechanism for derived classes to
|
||||
* do special things when there is a rematch.
|
||||
* This should be called to start a rematched game. It just starts the current game anew, but
|
||||
* provides a mechanism for derived classes to do special things when there is a rematch.
|
||||
*/
|
||||
public void rematchGame ()
|
||||
{
|
||||
@@ -86,10 +85,9 @@ public class CardGameManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived classes can override this method and take any action needed
|
||||
* prior to a game rematch. If the rematch needs to be vetoed for any
|
||||
* reason, they can return false from this method and the rematch will
|
||||
* be aborted.
|
||||
* Derived classes can override this method and take any action needed prior to a game
|
||||
* rematch. If the rematch needs to be vetoed for any reason, they can return false from this
|
||||
* method and the rematch will be aborted.
|
||||
*/
|
||||
protected boolean gameWillRematch ()
|
||||
{
|
||||
@@ -97,14 +95,13 @@ public class CardGameManager extends GameManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Deals a hand of cards to the player at the specified index from
|
||||
* the given Deck.
|
||||
* Deals a hand of cards to the player at the specified index from the given Deck.
|
||||
*
|
||||
* @param deck the deck from which to deal
|
||||
* @param size the size of the hand to deal
|
||||
* @param playerIndex the index of the target player
|
||||
* @return the hand dealt to the player, or null if the deal
|
||||
* was canceled because the deck did not contain enough cards
|
||||
* @return the hand dealt to the player, or null if the deal was canceled because the deck did
|
||||
* not contain enough cards
|
||||
*/
|
||||
public Hand dealHand (Deck deck, int size, int playerIndex)
|
||||
{
|
||||
@@ -122,16 +119,14 @@ public class CardGameManager extends GameManager
|
||||
return hand;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deals a hand of cards to each player from the specified
|
||||
* Deck.
|
||||
* Deals a hand of cards to each player from the specified Deck.
|
||||
*
|
||||
* @param deck the deck from which to deal
|
||||
* @param size the size of the hands to deal
|
||||
* @return the array of hands dealt to each player, or null if
|
||||
* the deal was canceled because the deck did not contain enough
|
||||
* cards
|
||||
* @return the array of hands dealt to each player, or null if the deal was canceled because
|
||||
* the deck did not contain enough cards
|
||||
*/
|
||||
public Hand[] dealHands (Deck deck, int size)
|
||||
{
|
||||
@@ -140,20 +135,18 @@ public class CardGameManager extends GameManager
|
||||
|
||||
} else {
|
||||
Hand[] hands = new Hand[_playerCount];
|
||||
|
||||
|
||||
for (int i=0;i<_playerCount;i++) {
|
||||
hands[i] = dealHand(deck, size, i);
|
||||
hands[i] = dealHand(deck, size, i);
|
||||
}
|
||||
|
||||
|
||||
return hands;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player index of the specified client object, or -1
|
||||
* if the client object does not represent a player. If the game has ended,
|
||||
* looks through the players of the now-ended game.
|
||||
*
|
||||
* Gets the player index of the specified client object, or -1 if the client object does not
|
||||
* represent a player. If the game has ended, looks through the players of the now-ended game.
|
||||
*/
|
||||
public int getPlayerIndex (ClientObject client)
|
||||
{
|
||||
@@ -167,21 +160,21 @@ public class CardGameManager extends GameManager
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the client object corresponding to the specified player index,
|
||||
* or null if the position is not occupied by a player.
|
||||
* Returns the client object corresponding to the specified player index, or null if the
|
||||
* position is not occupied by a player.
|
||||
*/
|
||||
public ClientObject getClientObject (int pidx)
|
||||
{
|
||||
if (_playerOids[pidx] != 0) {
|
||||
return (ClientObject)_omgr.getObject(_playerOids[pidx]);
|
||||
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a set of cards from one player to another.
|
||||
*
|
||||
@@ -197,51 +190,47 @@ public class CardGameManager extends GameManager
|
||||
if (fromClient != null) {
|
||||
CardGameSender.sentCardsToPlayer(fromClient, toPlayerIdx, cards);
|
||||
}
|
||||
|
||||
|
||||
// Notify the receiver with the cards
|
||||
ClientObject toClient = getClientObject(toPlayerIdx);
|
||||
if (toClient != null) {
|
||||
CardGameSender.sendCardsFromPlayer(toClient, fromPlayerIdx,
|
||||
cards);
|
||||
}
|
||||
|
||||
|
||||
// and everybody else in the room other than the sender and the
|
||||
// receiver with the number of cards sent
|
||||
notifyCardsTransferred(fromPlayerIdx, toPlayerIdx, cards.length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends sets of cards between players simultaneously. Each player is
|
||||
* guaranteed to receive the notification of cards received after the
|
||||
* notification of cards sent. The length of the arrays passed must
|
||||
* be equal to the player count.
|
||||
* Sends sets of cards between players simultaneously. Each player is guaranteed to receive
|
||||
* the notification of cards received after the notification of cards sent. The length of the
|
||||
* arrays passed must be equal to the player count.
|
||||
*
|
||||
* @param toPlayerIndices for each player, the index of the player to
|
||||
* transfer cards to
|
||||
* @param toPlayerIndices for each player, the index of the player to transfer cards to
|
||||
* @param cards for each player, the cards to transfer
|
||||
*/
|
||||
public void transferCardsBetweenPlayers (int[] toPlayerIndices,
|
||||
Card[][] cards)
|
||||
public void transferCardsBetweenPlayers (int[] toPlayerIndices, Card[][] cards)
|
||||
{
|
||||
// Send all removal notices
|
||||
for (int i = 0; i < _playerCount; i++) {
|
||||
ClientObject fromClient = getClientObject(i);
|
||||
for (int ii = 0; ii < _playerCount; ii++) {
|
||||
ClientObject fromClient = getClientObject(ii);
|
||||
if (fromClient != null) {
|
||||
CardGameSender.sentCardsToPlayer(fromClient,
|
||||
toPlayerIndices[i], cards[i]);
|
||||
CardGameSender.sentCardsToPlayer(fromClient, toPlayerIndices[ii], cards[ii]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Send all addition notices and notify everyone else
|
||||
for (int i = 0; i < _playerCount; i++) {
|
||||
ClientObject toClient = getClientObject(toPlayerIndices[i]);
|
||||
for (int ii = 0; ii < _playerCount; ii++) {
|
||||
ClientObject toClient = getClientObject(toPlayerIndices[ii]);
|
||||
if (toClient != null) {
|
||||
CardGameSender.sendCardsFromPlayer(toClient, i, cards[i]);
|
||||
CardGameSender.sendCardsFromPlayer(toClient, ii, cards[ii]);
|
||||
}
|
||||
notifyCardsTransferred(i, toPlayerIndices[i], cards[i].length);
|
||||
notifyCardsTransferred(ii, toPlayerIndices[ii], cards[ii].length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notifies everyone in the room (other than the sender and the receiver) that a set of cards
|
||||
* have been transferred.
|
||||
@@ -250,8 +239,8 @@ public class CardGameManager extends GameManager
|
||||
* @param toPlayerIdx the index of the player receiving the cards
|
||||
* @param cards the number of cards sent
|
||||
*/
|
||||
protected void notifyCardsTransferred (final int fromPlayerIdx,
|
||||
final int toPlayerIdx, final int cards)
|
||||
protected void notifyCardsTransferred (
|
||||
final int fromPlayerIdx, final int toPlayerIdx, final int cards)
|
||||
{
|
||||
final int senderOid = _playerOids[fromPlayerIdx],
|
||||
receiverOid = _playerOids[toPlayerIdx];
|
||||
@@ -269,7 +258,7 @@ public class CardGameManager extends GameManager
|
||||
};
|
||||
applyToOccupants(op);
|
||||
}
|
||||
|
||||
|
||||
/** The card game object. */
|
||||
protected CardGameObject _cardgameobj;
|
||||
|
||||
|
||||
+3
-5
@@ -25,8 +25,7 @@ import com.threerings.parlor.card.client.CardGameController;
|
||||
import com.threerings.parlor.turn.client.TurnGameControllerDelegate;
|
||||
|
||||
/**
|
||||
* A card game controller delegate for trick-based card games, such as
|
||||
* Spades and Hearts.
|
||||
* A card game controller delegate for trick-based card games, such as Spades and Hearts.
|
||||
*/
|
||||
public class TrickCardGameControllerDelegate
|
||||
extends TurnGameControllerDelegate
|
||||
@@ -36,13 +35,12 @@ public class TrickCardGameControllerDelegate
|
||||
*
|
||||
* @param controller the game controller
|
||||
*/
|
||||
public TrickCardGameControllerDelegate (CardGameController
|
||||
controller)
|
||||
public TrickCardGameControllerDelegate (CardGameController controller)
|
||||
{
|
||||
super(controller);
|
||||
_cgctrl = controller;
|
||||
}
|
||||
|
||||
|
||||
/** The card game controller. */
|
||||
protected CardGameController _cgctrl;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface TrickCardGameService extends InvocationService
|
||||
* @param cards the cards to send
|
||||
*/
|
||||
public void sendCardsToPlayer (Client client, int toidx, Card[] cards);
|
||||
|
||||
|
||||
/**
|
||||
* Plays a card in the trick.
|
||||
*
|
||||
@@ -49,7 +49,7 @@ public interface TrickCardGameService extends InvocationService
|
||||
* that the request is for the current trick
|
||||
*/
|
||||
public void playCard (Client client, Card card, int handSize);
|
||||
|
||||
|
||||
/**
|
||||
* A request for a rematch.
|
||||
*
|
||||
|
||||
@@ -30,13 +30,13 @@ public interface TrickCardCodes extends CardCodes
|
||||
{
|
||||
/** For four-player games, the bottom (own) player. */
|
||||
public static final int BOTTOM = 0;
|
||||
|
||||
|
||||
/** For four-player games, the player on the left. */
|
||||
public static final int LEFT = 1;
|
||||
|
||||
|
||||
/** For four-player games, the top (opposite) player. */
|
||||
public static final int TOP = 2;
|
||||
|
||||
|
||||
/** For four-player games, the player on the right. */
|
||||
public static final int RIGHT = 3;
|
||||
}
|
||||
|
||||
@@ -33,25 +33,25 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
{
|
||||
/** The state that indicates the game is currently between hands. */
|
||||
public static final int BETWEEN_HANDS = 0;
|
||||
|
||||
|
||||
/** The state that indicates the game is currently playing a hand. */
|
||||
public static final int PLAYING_HAND = 1;
|
||||
|
||||
|
||||
/** The state that indicates the game is currently playing a trick. */
|
||||
public static final int PLAYING_TRICK = 2;
|
||||
|
||||
|
||||
/** The number of states defined for the base trick card game object. */
|
||||
public static final int TRICK_STATE_COUNT = 3;
|
||||
|
||||
|
||||
/** Indicates that the player has not requested or accepted a rematch. */
|
||||
public static final int NO_REQUEST = 0;
|
||||
|
||||
|
||||
/** Indicates that the player has requested a rematch. */
|
||||
public static final int REQUESTS_REMATCH = 1;
|
||||
|
||||
|
||||
/** Indicates that the player has accepted the rematch request. */
|
||||
public static final int ACCEPTS_REMATCH = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a reference to the trick card game service used to make
|
||||
* requests to the server.
|
||||
@@ -59,7 +59,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return a reference to the trick card game service
|
||||
*/
|
||||
public TrickCardGameMarshaller getTrickCardGameService ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the reference to the trick card game service.
|
||||
*
|
||||
@@ -67,7 +67,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
*/
|
||||
public void setTrickCardGameService (TrickCardGameMarshaller
|
||||
trickCardGameService);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the field that contains the trick state: between
|
||||
* hands, playing a hand, or playing a trick.
|
||||
@@ -75,7 +75,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the name of the trickState field
|
||||
*/
|
||||
public String getTrickStateFieldName ();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the trick state: between hands, playing a hand, or playing a
|
||||
* trick.
|
||||
@@ -88,9 +88,9 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* Sets the trick state.
|
||||
*
|
||||
* @param trickState the trick state
|
||||
*/
|
||||
*/
|
||||
public void setTrickState (int trickState);
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array containing the turn duration scales for each player.
|
||||
* Turn duration scales decrease each time players time out.
|
||||
@@ -98,14 +98,14 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the array of turn duration scales
|
||||
*/
|
||||
public float[] getTurnDurationScales ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the array of turn duration scales.
|
||||
*
|
||||
* @param turnDurationScales the array of turn duration scales
|
||||
*/
|
||||
public void setTurnDurationScales (float[] turnDurationScales);
|
||||
|
||||
|
||||
/**
|
||||
* Sets an element of the array of turn duration scales.
|
||||
*
|
||||
@@ -113,13 +113,13 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @param index the index of the turn duration scale
|
||||
*/
|
||||
public void setTurnDurationScalesAt (float turnDurationScale, int index);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the duration of the current turn, which may depend on the state
|
||||
* of the game as well as the duration scale of the active player.
|
||||
*/
|
||||
public long getTurnDuration ();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the field that contains the history of the trick
|
||||
* in terms of the cards played by each player.
|
||||
@@ -127,7 +127,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the name of the cardsPlayed field
|
||||
*/
|
||||
public String getCardsPlayedFieldName ();
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array containing the history of the trick in terms of the
|
||||
* cards played by each player.
|
||||
@@ -135,7 +135,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the cards played so far in the trick
|
||||
*/
|
||||
public PlayerCard[] getCardsPlayed ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the array of cards played by each player.
|
||||
*
|
||||
@@ -150,7 +150,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the name of the lastCardsPlayed field
|
||||
*/
|
||||
public String getLastCardsPlayedFieldName ();
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array containing the history of the last trick in terms of
|
||||
* the cards played by each player.
|
||||
@@ -158,35 +158,35 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @return the cards played in the last trick
|
||||
*/
|
||||
public PlayerCard[] getLastCardsPlayed ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the last array of cards played by each player.
|
||||
*
|
||||
* @param lastCardsPlayed the last array of cards played
|
||||
*/
|
||||
public void setLastCardsPlayed (PlayerCard[] lastCardsPlayed);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the field that contains the rematch requests.
|
||||
*
|
||||
* @return the name of the rematchRequests field
|
||||
*/
|
||||
public String getRematchRequestsFieldName ();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the array of rematch requests.
|
||||
*
|
||||
* @return the array of rematch requests
|
||||
*/
|
||||
public int[] getRematchRequests ();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the array of rematch requests.
|
||||
*
|
||||
* @param rematchRequests the array of rematch requests
|
||||
*/
|
||||
public void setRematchRequests (int[] rematchRequests);
|
||||
|
||||
|
||||
/**
|
||||
* Sets an element of the rematch request array.
|
||||
*
|
||||
@@ -194,7 +194,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @param index the index at which to set the value
|
||||
*/
|
||||
public void setRematchRequestsAt (int rematchRequest, int index);
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether a user can play the specified card at this time.
|
||||
*
|
||||
@@ -202,7 +202,7 @@ public interface TrickCardGameObject extends TurnGameObject
|
||||
* @param card the card that the user would like to play
|
||||
*/
|
||||
public boolean isCardPlayable (Hand hand, Card card);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the card of the player who took the current trick.
|
||||
*/
|
||||
|
||||
+12
-17
@@ -28,8 +28,6 @@ import java.util.List;
|
||||
import com.samskivert.util.ArrayUtil;
|
||||
import com.samskivert.util.Interval;
|
||||
import com.samskivert.util.RandomUtil;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
@@ -215,15 +213,15 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
// make sure they're actually a player
|
||||
int fromidx = _cgmgr.getPlayerIndex(client);
|
||||
if (fromidx == -1) {
|
||||
log.warning("Send request from non-player [username=" +
|
||||
((BodyObject)client).who() + ", cards=" + StringUtil.toString(cards) + "].");
|
||||
log.warning("Send request from non-player",
|
||||
"username", ((BodyObject)client).who(), "cards", cards);
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure they have the cards
|
||||
if (!_hands[fromidx].containsAll(cards)) {
|
||||
log.warning("Tried to send cards not held [username=" +
|
||||
((BodyObject)client).who() + ", cards=" + StringUtil.toString(cards) + "].");
|
||||
log.warning("Tried to send cards not held",
|
||||
"username", ((BodyObject)client).who(), "cards", cards);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,15 +251,13 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
|
||||
// make sure their hand contains the specified card
|
||||
if (!_hands[pidx].contains(card)) {
|
||||
log.warning("Tried to play card not held [username=" + username +
|
||||
", card=" + card + "].");
|
||||
log.warning("Tried to play card not held", "username", username, "card", card);
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the card is legal to play
|
||||
if (!_trickCardGame.isCardPlayable(_hands[pidx], card)) {
|
||||
log.warning("Tried to play illegal card [username=" + username +
|
||||
", card=" + card + "].");
|
||||
log.warning("Tried to play illegal card", "username", username, "card", card);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -281,14 +277,13 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
// make sure the requester is one of the players
|
||||
int pidx = _cgmgr.getPlayerIndex(client);
|
||||
if (pidx == -1) {
|
||||
log.warning("Rematch request from non-player [username=" +
|
||||
((BodyObject)client).who() + "].");
|
||||
log.warning("Rematch request from non-player", "username", ((BodyObject)client).who());
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the player hasn't already requested
|
||||
if (_trickCardGame.getRematchRequests()[pidx] != TrickCardGameObject.NO_REQUEST) {
|
||||
log.warning("Repeated rematch request [username=" + ((BodyObject)client).who() + "].");
|
||||
log.warning("Repeated rematch request", "username", ((BodyObject)client).who());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -361,8 +356,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
{
|
||||
int[] rematchRequests = _trickCardGame.getRematchRequests();
|
||||
int count = 0;
|
||||
for (int i = 0; i < rematchRequests.length; i++) {
|
||||
if (rematchRequests[i] != TrickCardGameObject.NO_REQUEST) {
|
||||
for (int rematchRequest : rematchRequests) {
|
||||
if (rematchRequest != TrickCardGameObject.NO_REQUEST) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -562,8 +557,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
*/
|
||||
protected boolean anyHandsEmpty ()
|
||||
{
|
||||
for (int i = 0; i < _hands.length; i++) {
|
||||
if (_hands[i].isEmpty()) {
|
||||
for (Hand _hand : _hands) {
|
||||
if (_hand.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ public class TrickCardGameUtil
|
||||
implements TrickCardCodes
|
||||
{
|
||||
/**
|
||||
* For four-player games with fixed partnerships, this returns the index
|
||||
* of the player's team.
|
||||
* For four-player games with fixed partnerships, this returns the index of the player's team.
|
||||
*
|
||||
* @param pidx the player index
|
||||
*/
|
||||
@@ -42,10 +41,9 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return pidx & 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games with fixed partnerships, this returns the index
|
||||
* of the other team.
|
||||
* For four-player games with fixed partnerships, this returns the index of the other team.
|
||||
*
|
||||
* @param tidx the index of the team
|
||||
*/
|
||||
@@ -53,19 +51,19 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return tidx ^ 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games with fixed partnerships, this returns the index
|
||||
* of the player's partner.
|
||||
* For four-player games with fixed partnerships, this returns the index of the player's
|
||||
* partner.
|
||||
*/
|
||||
public static int getPartnerIndex (int pidx)
|
||||
{
|
||||
return pidx ^ 2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games with fixed partnerships, this returns the index
|
||||
* of one of the members of a team.
|
||||
* For four-player games with fixed partnerships, this returns the index of one of the members
|
||||
* of a team.
|
||||
*
|
||||
* @param tidx the index of the team
|
||||
* @param midx the index of the player within the team
|
||||
@@ -74,10 +72,10 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return (midx << 1) | tidx;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games, this returns the index of the player after the
|
||||
* specified player going clockwise around the table.
|
||||
* For four-player games, this returns the index of the player after the specified player
|
||||
* going clockwise around the table.
|
||||
*/
|
||||
public static int getNextInClockwiseSequence (int pidx)
|
||||
{
|
||||
@@ -86,10 +84,10 @@ public class TrickCardGameUtil
|
||||
// 0
|
||||
return (pidx + 1) & 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games with fixed partnerships, this returns the
|
||||
* relative location of one player from the point of view of another.
|
||||
* For four-player games with fixed partnerships, this returns the relative location of one
|
||||
* player from the point of view of another.
|
||||
*
|
||||
* @param pidx1 the index of the player to whom the location is relative
|
||||
* @param pidx2 the index of the player whose location is desired
|
||||
@@ -99,34 +97,32 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return (pidx2 - pidx1) & 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games, returns the index of the player to the left of
|
||||
* the specified player.
|
||||
* For four-player games, returns the index of the player to the left of the specified player.
|
||||
*/
|
||||
public static int getLeftIndex (int pidx)
|
||||
{
|
||||
return (pidx + 1) & 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games, returns the index of the player to the right of
|
||||
* the specified player.
|
||||
* For four-player games, returns the index of the player to the right of the specified
|
||||
* player.
|
||||
*/
|
||||
public static int getRightIndex (int pidx)
|
||||
{
|
||||
return (pidx + 3) & 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For four-player games, returns the index of the player across from the
|
||||
* specified player.
|
||||
* For four-player games, returns the index of the player across from the specified player.
|
||||
*/
|
||||
public static int getOppositeIndex (int pidx)
|
||||
{
|
||||
return pidx ^ 2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the player can follow the suit lead with the hand given.
|
||||
*/
|
||||
@@ -134,35 +130,34 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return hand.getSuitMemberCount(cardsPlayed[0].card.getSuit()) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the specified array contains the given card.
|
||||
*/
|
||||
public static boolean containsCard (PlayerCard[] cards, Card card)
|
||||
{
|
||||
for (int i = 0; i < cards.length; i++) {
|
||||
if (cards[i].card.equals(card)) {
|
||||
for (PlayerCard pc : cards) {
|
||||
if (pc.card.equals(card)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines the number of cards that belong to the specified suit within
|
||||
* the array given.
|
||||
* Determines the number of cards that belong to the specified suit within the array given.
|
||||
*/
|
||||
public static int countSuitMembers (PlayerCard[] cards, int suit)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < cards.length; i++) {
|
||||
if (cards[i].card.getSuit() == suit) {
|
||||
for (PlayerCard pc : cards) {
|
||||
if (pc.card.getSuit() == suit) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the proposed card follows the suit lead.
|
||||
*/
|
||||
@@ -170,23 +165,21 @@ public class TrickCardGameUtil
|
||||
{
|
||||
return cardsPlayed[0].card.getSuit() == card.getSuit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the highest card (according to the standard A,K,...,2 ordering)
|
||||
* in the suit lead, with an optional trump suit.
|
||||
* Returns the highest card (according to the standard A,K,...,2 ordering) in the suit lead,
|
||||
* with an optional trump suit.
|
||||
*
|
||||
* @param trumpSuit the trump suit, or -1 for none
|
||||
*/
|
||||
public static PlayerCard getHighestInLeadSuit (PlayerCard[] cardsPlayed,
|
||||
int trumpSuit)
|
||||
public static PlayerCard getHighestInLeadSuit (PlayerCard[] cardsPlayed, int trumpSuit)
|
||||
{
|
||||
PlayerCard highest = cardsPlayed[0];
|
||||
for (int i = 1; i < cardsPlayed.length; i++) {
|
||||
PlayerCard other = cardsPlayed[i];
|
||||
if ((other.card.getSuit() == highest.card.getSuit() &&
|
||||
other.card.compareTo(highest.card) > 0) ||
|
||||
(other.card.getSuit() == trumpSuit &&
|
||||
highest.card.getSuit() != trumpSuit)) {
|
||||
(other.card.getSuit() == trumpSuit && highest.card.getSuit() != trumpSuit)) {
|
||||
highest = other;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public abstract class TableConfigurator
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, the TableConfigurator is empty, which doesn't mean that
|
||||
* If true, the TableConfigurator is empty, which doesn't mean that
|
||||
* it will not return a TableConfig object (for it must), but rather
|
||||
* that there are no user-editable options being presented in the
|
||||
* config interface.
|
||||
|
||||
@@ -303,7 +303,7 @@ public class TableManager
|
||||
} else if ( ! _allowBooting) {
|
||||
throw new InvocationException(INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
|
||||
int position = ListUtil.indexOf(table.players, target);
|
||||
if (position < 0) {
|
||||
throw new InvocationException(NOT_AT_TABLE);
|
||||
|
||||
@@ -24,7 +24,7 @@ package com.threerings.parlor.tourney.data;
|
||||
import com.threerings.io.SimpleStreamableObject;
|
||||
|
||||
/**
|
||||
* Extensible class that specifies the prize for a tourney.
|
||||
* Extensible class that specifies the prize for a tourney.
|
||||
*/
|
||||
public abstract class Prize extends SimpleStreamableObject
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.threerings.io.SimpleStreamableObject;
|
||||
import com.threerings.util.Name;
|
||||
|
||||
/**
|
||||
* Stores tournament configuration data.
|
||||
* Stores tournament configuration data.
|
||||
*/
|
||||
public class TourneyConfig extends SimpleStreamableObject
|
||||
{
|
||||
|
||||
@@ -73,7 +73,7 @@ public abstract class TourniesManager
|
||||
}
|
||||
|
||||
// from interface TourniesService
|
||||
public void createTourney (ClientObject caller, TourneyConfig config,
|
||||
public void createTourney (ClientObject caller, TourneyConfig config,
|
||||
final InvocationService.ResultListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user