Various changes for style, changes to Card recommended by Ray.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3136 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2004-10-15 00:14:23 +00:00
parent 9bbd46fa7b
commit 73f44a5ee3
14 changed files with 212 additions and 255 deletions
@@ -1,5 +1,5 @@
// //
// $Id: OrientableImageSprite.java,v 1.1 2004/10/13 02:03:44 andrzej Exp $ // $Id: OrientableImageSprite.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -21,9 +21,11 @@
package com.threerings.media.sprite; package com.threerings.media.sprite;
import java.awt.*; import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.*; import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.image.*; import java.awt.image.*;
@@ -40,7 +42,7 @@ public class OrientableImageSprite extends ImageSprite
/** /**
* Creates a new orientable image sprite. * Creates a new orientable image sprite.
*/ */
public OrientableImageSprite() public OrientableImageSprite ()
{} {}
/** /**
@@ -48,7 +50,7 @@ public class OrientableImageSprite extends ImageSprite
* *
* @param image the image to render * @param image the image to render
*/ */
public OrientableImageSprite(Mirage image) public OrientableImageSprite (Mirage image)
{ {
super(image); super(image);
} }
@@ -58,7 +60,7 @@ public class OrientableImageSprite extends ImageSprite
* *
* @param frames the frames to render * @param frames the frames to render
*/ */
public OrientableImageSprite(MultiFrameImage frames) public OrientableImageSprite (MultiFrameImage frames)
{ {
super(frames); super(frames);
} }
@@ -69,7 +71,7 @@ public class OrientableImageSprite extends ImageSprite
* *
* @return the newly computed rotation transform * @return the newly computed rotation transform
*/ */
private AffineTransform getRotationTransform() private AffineTransform getRotationTransform ()
{ {
double theta; double theta;
@@ -149,7 +151,7 @@ public class OrientableImageSprite extends ImageSprite
} }
// Documentation inherited. // Documentation inherited.
protected void accomodateFrame(int frameIdx, int width, int height) protected void accomodateFrame (int frameIdx, int width, int height)
{ {
Area area = new Area( Area area = new Area(
new Rectangle( new Rectangle(
@@ -166,7 +168,7 @@ public class OrientableImageSprite extends ImageSprite
} }
// Documentation inherited. // Documentation inherited.
public void setOrientation(int orient) public void setOrientation (int orient)
{ {
super.setOrientation(orient); super.setOrientation(orient);
@@ -174,14 +176,13 @@ public class OrientableImageSprite extends ImageSprite
} }
// Documentation inherited. // Documentation inherited.
public void paint(Graphics2D graphics) public void paint (Graphics2D graphics)
{ {
AffineTransform at = graphics.getTransform(); AffineTransform at = graphics.getTransform();
graphics.transform(getRotationTransform()); graphics.transform(getRotationTransform());
if(_frames != null) if(_frames != null) {
{
_frames.paintFrame( _frames.paintFrame(
graphics, graphics,
_frameIdx, _frameIdx,
@@ -189,8 +190,7 @@ public class OrientableImageSprite extends ImageSprite
_oy - _oyoff _oy - _oyoff
); );
} }
else else {
{
super.paint(graphics); super.paint(graphics);
} }
@@ -1,5 +1,5 @@
// //
// $Id: CardGameController.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: CardGameController.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -44,7 +44,7 @@ public abstract class CardGameController extends GameController
CardCodes CardCodes
{ {
// Documentation inhertied // Documentation inhertied
public void init(CrowdContext context, PlaceConfig config) public void init (CrowdContext context, PlaceConfig config)
{ {
super.init(context, config); super.init(context, config);
@@ -52,7 +52,7 @@ public abstract class CardGameController extends GameController
} }
// Documentation inherited // Documentation inherited
public void messageReceived(MessageEvent event) public void messageReceived (MessageEvent event)
{ {
if(event.getName().equals(TAKE_HAND)) if(event.getName().equals(TAKE_HAND))
{ {
@@ -65,6 +65,6 @@ public abstract class CardGameController extends GameController
* *
* @param hand the hand dealt to the user * @param hand the hand dealt to the user
*/ */
protected void handDealt(Hand hand) protected void handDealt (Hand hand)
{} {}
} }
@@ -1,5 +1,5 @@
// //
// $Id: CardPanel.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: CardPanel.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -52,18 +52,18 @@ public abstract class CardPanel extends VirtualMediaPanel
/** Calls CardSpriteObserver.cardSpriteClicked. */ /** Calls CardSpriteObserver.cardSpriteClicked. */
protected static class CardSpriteClickedOp implements ObserverList.ObserverOp protected static class CardSpriteClickedOp implements ObserverList.ObserverOp
{ {
protected CardSprite sprite; protected CardSprite _sprite;
protected MouseEvent me; protected MouseEvent _me;
public CardSpriteClickedOp(CardSprite sprite, MouseEvent me) public CardSpriteClickedOp (CardSprite sprite, MouseEvent me)
{ {
this.sprite = sprite; _sprite = sprite;
this.me = me; _me = me;
} }
public boolean apply(Object observer) public boolean apply (Object observer)
{ {
((CardSpriteObserver)observer).cardSpriteClicked(sprite, me); ((CardSpriteObserver)observer).cardSpriteClicked(_sprite, _me);
return true; return true;
} }
} }
@@ -71,18 +71,18 @@ public abstract class CardPanel extends VirtualMediaPanel
/** Calls CardSpriteObserver.cardSpriteDragged. */ /** Calls CardSpriteObserver.cardSpriteDragged. */
protected static class CardSpriteDraggedOp implements ObserverList.ObserverOp protected static class CardSpriteDraggedOp implements ObserverList.ObserverOp
{ {
protected CardSprite sprite; protected CardSprite _sprite;
protected MouseEvent me; protected MouseEvent _me;
public CardSpriteDraggedOp(CardSprite sprite, MouseEvent me) public CardSpriteDraggedOp (CardSprite sprite, MouseEvent me)
{ {
this.sprite = sprite; _sprite = sprite;
this.me = me; _me = me;
} }
public boolean apply(Object observer) public boolean apply (Object observer)
{ {
((CardSpriteObserver)observer).cardSpriteDragged(sprite, me); ((CardSpriteObserver)observer).cardSpriteDragged(_sprite, _me);
return true; return true;
} }
} }
@@ -93,14 +93,14 @@ public abstract class CardPanel extends VirtualMediaPanel
* *
* @param frameManager the frame manager * @param frameManager the frame manager
*/ */
public CardPanel(FrameManager frameManager) public CardPanel (FrameManager frameManager)
{ {
super(frameManager); super(frameManager);
addMouseListener( addMouseListener(
new MouseAdapter() new MouseAdapter()
{ {
public void mousePressed(MouseEvent me) public void mousePressed (MouseEvent me)
{ {
ArrayList al = new ArrayList(); ArrayList al = new ArrayList();
@@ -128,38 +128,38 @@ public abstract class CardPanel extends VirtualMediaPanel
} }
} }
activeCardSprite = highestSprite; _activeCardSprite = highestSprite;
if(activeCardSprite != null) if(_activeCardSprite != null)
{ {
handleX = activeCardSprite.getX() - me.getX(); _handleX = _activeCardSprite.getX() - me.getX();
handleY = activeCardSprite.getY() - me.getY(); _handleY = _activeCardSprite.getY() - me.getY();
hasBeenDragged = false; _hasBeenDragged = false;
} }
} }
else else
{ {
activeCardSprite = null; _activeCardSprite = null;
} }
} }
public void mouseReleased(MouseEvent me) public void mouseReleased (MouseEvent me)
{ {
if(activeCardSprite != null && hasBeenDragged) if(_activeCardSprite != null && _hasBeenDragged)
{ {
activeCardSprite.queueNotification( _activeCardSprite.queueNotification(
new CardSpriteDraggedOp(activeCardSprite, me) new CardSpriteDraggedOp(_activeCardSprite, me)
); );
} }
} }
public void mouseClicked(MouseEvent me) public void mouseClicked (MouseEvent me)
{ {
if(activeCardSprite != null) if(_activeCardSprite != null)
{ {
activeCardSprite.queueNotification( _activeCardSprite.queueNotification(
new CardSpriteClickedOp(activeCardSprite, me) new CardSpriteClickedOp(_activeCardSprite, me)
); );
} }
} }
@@ -169,17 +169,17 @@ public abstract class CardPanel extends VirtualMediaPanel
addMouseMotionListener( addMouseMotionListener(
new MouseMotionAdapter() new MouseMotionAdapter()
{ {
public void mouseDragged(MouseEvent me) public void mouseDragged (MouseEvent me)
{ {
if(activeCardSprite != null && if(_activeCardSprite != null &&
activeCardSprite.isDraggable()) _activeCardSprite.isDraggable())
{ {
activeCardSprite.setLocation( _activeCardSprite.setLocation(
me.getX() + handleX, me.getX() + _handleX,
me.getY() + handleY me.getY() + _handleY
); );
hasBeenDragged = true; _hasBeenDragged = true;
} }
} }
} }
@@ -191,7 +191,7 @@ public abstract class CardPanel extends VirtualMediaPanel
* *
* @return the card back image * @return the card back image
*/ */
public abstract Mirage getCardBackImage(); public abstract Mirage getCardBackImage ();
/** /**
* Returns the image for the front of the specified card. * Returns the image for the front of the specified card.
@@ -199,15 +199,15 @@ public abstract class CardPanel extends VirtualMediaPanel
* @param card the desired card * @param card the desired card
* @return the card front image * @return the card front image
*/ */
public abstract Mirage getCardImage(Card card); public abstract Mirage getCardImage (Card card);
/** The last card sprite pressed. */ /** The last card sprite pressed. */
private CardSprite activeCardSprite; protected CardSprite _activeCardSprite;
/** The location of the cursor in the active sprite. */ /** The location of the cursor in the active sprite. */
private int handleX, handleY; protected int _handleX, _handleY;
/** Whether or not the active sprite has been dragged. */ /** Whether or not the active sprite has been dragged. */
private boolean hasBeenDragged; protected boolean _hasBeenDragged;
} }
@@ -1,5 +1,5 @@
// //
// $Id: CardSprite.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: CardSprite.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -32,26 +32,13 @@ import com.threerings.parlor.card.data.Card;
*/ */
public class CardSprite extends OrientableImageSprite public class CardSprite extends OrientableImageSprite
{ {
/** The panel responsible for the sprite. */
protected CardPanel _panel;
/** The depicted card. */
protected Card _card;
/** Whether or not the card is facing up. */
protected boolean _facingUp;
/** Whether or not the user can drag the card around the board. */
protected boolean _draggable;
/** /**
* Creates a new upward-facing card sprite. * Creates a new upward-facing card sprite.
* *
* @param panel the panel responsible for the sprite * @param panel the panel responsible for the sprite
* @param card the card to depict * @param card the card to depict
*/ */
public CardSprite(CardPanel panel, Card card) public CardSprite (CardPanel panel, Card card)
{ {
_panel = panel; _panel = panel;
_card = card; _card = card;
@@ -67,7 +54,7 @@ public class CardSprite extends OrientableImageSprite
* @param card the card to depict * @param card the card to depict
* @param facingUp whether or not the card should be facing up * @param facingUp whether or not the card should be facing up
*/ */
public CardSprite(CardPanel panel, Card card, boolean facingUp) public CardSprite (CardPanel panel, Card card, boolean facingUp)
{ {
_panel = panel; _panel = panel;
_card = card; _card = card;
@@ -81,7 +68,7 @@ public class CardSprite extends OrientableImageSprite
* *
* @param card the new card * @param card the new card
*/ */
public void setCard(Card card) public void setCard (Card card)
{ {
_card = card; _card = card;
@@ -93,7 +80,7 @@ public class CardSprite extends OrientableImageSprite
* *
* @return the current card * @return the current card
*/ */
public Card getCard() public Card getCard ()
{ {
return _card; return _card;
} }
@@ -103,7 +90,7 @@ public class CardSprite extends OrientableImageSprite
* *
* @param facingUp whether or not the card should be facing up * @param facingUp whether or not the card should be facing up
*/ */
public void setFacingUp(boolean facingUp) public void setFacingUp (boolean facingUp)
{ {
_facingUp = facingUp; _facingUp = facingUp;
@@ -115,7 +102,7 @@ public class CardSprite extends OrientableImageSprite
* *
* @return true if the card is facing up, false if facing down * @return true if the card is facing up, false if facing down
*/ */
public boolean isFacingUp() public boolean isFacingUp ()
{ {
return _facingUp; return _facingUp;
} }
@@ -125,7 +112,7 @@ public class CardSprite extends OrientableImageSprite
* *
* @param draggable whether or not the user can drag the card * @param draggable whether or not the user can drag the card
*/ */
public void setDraggable(boolean draggable) public void setDraggable (boolean draggable)
{ {
_draggable = draggable; _draggable = draggable;
} }
@@ -135,7 +122,7 @@ public class CardSprite extends OrientableImageSprite
* *
* @return true if the user can drag the card, false if not * @return true if the user can drag the card, false if not
*/ */
public boolean isDraggable() public boolean isDraggable ()
{ {
return _draggable; return _draggable;
} }
@@ -143,8 +130,21 @@ public class CardSprite extends OrientableImageSprite
/** /**
* Updates the mirage according to the current state. * Updates the mirage according to the current state.
*/ */
private void updateMirage() private void updateMirage ()
{ {
setMirage(_facingUp ? _panel.getCardImage(_card) : _panel.getCardBackImage()); setMirage(_facingUp ? _panel.getCardImage(_card) : _panel.getCardBackImage());
} }
/** The panel responsible for the sprite. */
protected CardPanel _panel;
/** The depicted card. */
protected Card _card;
/** Whether or not the card is facing up. */
protected boolean _facingUp;
/** Whether or not the user can drag the card around the board. */
protected boolean _draggable;
} }
@@ -1,5 +1,5 @@
// //
// $Id: CardSpriteObserver.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: CardSpriteObserver.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -21,7 +21,7 @@
package com.threerings.parlor.card.client; package com.threerings.parlor.card.client;
import java.awt.event.*; import java.awt.event.MouseEvent;
/** /**
* Observer interface for (draggable) card sprites. * Observer interface for (draggable) card sprites.
@@ -34,7 +34,7 @@ public interface CardSpriteObserver
* @param sprite the dragged sprite * @param sprite the dragged sprite
* @param me the mouse event associated with the drag * @param me the mouse event associated with the drag
*/ */
public void cardSpriteClicked(CardSprite sprite, MouseEvent me); public void cardSpriteClicked (CardSprite sprite, MouseEvent me);
/** /**
* Notifies the observer that the user dragged a card sprite to a new * Notifies the observer that the user dragged a card sprite to a new
@@ -43,5 +43,5 @@ public interface CardSpriteObserver
* @param sprite the dragged sprite * @param sprite the dragged sprite
* @param me the mouse event associated with the drag * @param me the mouse event associated with the drag
*/ */
public void cardSpriteDragged(CardSprite sprite, MouseEvent me); public void cardSpriteDragged (CardSprite sprite, MouseEvent me);
} }
@@ -1,5 +1,5 @@
// //
// $Id: Card.java,v 1.2 2004/10/13 19:29:12 andrzej Exp $ // $Id: Card.java,v 1.3 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -38,7 +38,7 @@ public class Card implements CardCodes,
/** /**
* No-arg constructor for deserialization. * No-arg constructor for deserialization.
*/ */
public Card() public Card ()
{} {}
/** /**
@@ -47,9 +47,9 @@ public class Card implements CardCodes,
* *
* @return the value of the card * @return the value of the card
*/ */
public int getNumber() public int getNumber ()
{ {
return number; return (_value >> 2);
} }
/** /**
@@ -58,9 +58,9 @@ public class Card implements CardCodes,
* *
* @return the suit of the card * @return the suit of the card
*/ */
public int getSuit() public int getSuit ()
{ {
return suit; return (_value & 0x03);
} }
/** /**
@@ -68,8 +68,10 @@ public class Card implements CardCodes,
* *
* @return true if the card is a number card, false otherwise * @return true if the card is a number card, false otherwise
*/ */
public boolean isNumber() public boolean isNumber ()
{ {
int number = getNumber();
return number >= 2 && number <= 10; return number >= 2 && number <= 10;
} }
@@ -78,8 +80,10 @@ public class Card implements CardCodes,
* *
* @return true if the card is a face card, false otherwise * @return true if the card is a face card, false otherwise
*/ */
public boolean isFace() public boolean isFace ()
{ {
int number = getNumber();
return number == KING || number == QUEEN || number == JACK; return number == KING || number == QUEEN || number == JACK;
} }
@@ -88,9 +92,9 @@ public class Card implements CardCodes,
* *
* @return true if the card is an ace, false otherwise * @return true if the card is an ace, false otherwise
*/ */
public boolean isAce() public boolean isAce ()
{ {
return number == ACE; return getNumber() == ACE;
} }
/** /**
@@ -98,9 +102,9 @@ public class Card implements CardCodes,
* *
* @return true if the card is a joker, false otherwise * @return true if the card is a joker, false otherwise
*/ */
public boolean isJoker() public boolean isJoker ()
{ {
return number == JOKER; return getNumber() == JOKER;
} }
/** /**
@@ -109,48 +113,24 @@ public class Card implements CardCodes,
* *
* @return true if this card is valid, false if not * @return true if this card is valid, false if not
*/ */
public boolean isValid() public boolean isValid ()
{ {
int number = getNumber(), suit = getSuit();
return number == JOKER || return number == JOKER ||
(number >= 2 && number <= ACE && (number >= 2 && number <= ACE &&
suit >= HEARTS && suit <= SPADES); suit >= HEARTS && suit <= SPADES);
} }
/** // Documentation inherited.
* Writes this object to the specified output stream. public Comparable getKey ()
*
* @param oos the output stream
*/
public void writeObject(ObjectOutputStream oos)
throws IOException
{ {
oos.defaultWriteObject(); if(_key == null)
{
_key = new Byte(_value);
}
oos.writeInt(number); return _key;
oos.writeInt(suit);
}
/**
* Reads this object from the specified input stream.
*
* @param ois the input stream
*/
public void readObject(ObjectInputStream ois)
throws IOException,
ClassNotFoundException
{
ois.defaultReadObject();
number = ois.readInt();
suit = ois.readInt();
key = new Integer((number << 2) | suit);
}
// documentation inherited
public Comparable getKey()
{
return key;
} }
/** /**
@@ -158,9 +138,9 @@ public class Card implements CardCodes,
* *
* @return this card's hash code * @return this card's hash code
*/ */
public int hashCode() public int hashCode ()
{ {
return key.intValue(); return _value;
} }
/** /**
@@ -169,12 +149,11 @@ public class Card implements CardCodes,
* @param other the other card to compare * @param other the other card to compare
* @return true if the cards are equal, false otherwise * @return true if the cards are equal, false otherwise
*/ */
public boolean equals(Object other) public boolean equals (Object other)
{ {
if(other instanceof Card) if(other instanceof Card)
{ {
return number == ((Card)other).number && return _value == ((Card)other)._value;
suit == ((Card)other).suit;
} }
else else
{ {
@@ -182,66 +161,50 @@ public class Card implements CardCodes,
} }
} }
/**
* Returns a string representation of a given number.
*
* @param number the number to represent
* @return the string representation
*/
public static String numberToString(int number)
{
switch(number)
{
case 2: return "Two";
case 3: return "Three";
case 4: return "Four";
case 5: return "Five";
case 6: return "Six";
case 7: return "Seven";
case 8: return "Eight";
case 9: return "Nine";
case 10: return "Ten";
case JACK: return "Jack";
case QUEEN: return "Queen";
case KING: return "King";
case ACE: return "Ace";
case JOKER: return "Joker";
default: return "???";
}
}
/**
* Returns a string representation of a particular suit.
*
* @param suit the suit to represent
* @return the string representation
*/
public static String suitToString(int suit)
{
switch(suit)
{
case HEARTS: return "Hearts";
case DIAMONDS: return "Diamonds";
case CLUBS: return "Clubs";
case SPADES: return "Spades";
default: return "???";
}
}
/** /**
* Returns a string representation of this card. * Returns a string representation of this card.
* *
* @return a description of this card * @return a description of this card
*/ */
public String toString() public String toString ()
{ {
int number = getNumber();
if(number == JOKER) if(number == JOKER)
{ {
return "Joker"; return "Jk";
} }
else else
{ {
return numberToString(number) + " of " + suitToString(suit); StringBuffer sb = new StringBuffer();
if(number >= 2 && number <= 9)
{
sb.append(Integer.toString(number));
}
else
{
switch(number)
{
case 10: sb.append('T'); break;
case JACK: sb.append('J'); break;
case QUEEN: sb.append('Q'); break;
case KING: sb.append('K'); break;
case ACE: sb.append('A'); break;
default: sb.append('?'); break;
}
}
switch(getSuit())
{
case HEARTS: sb.append('h'); break;
case DIAMONDS: sb.append('d'); break;
case CLUBS: sb.append('c'); break;
case SPADES: sb.append('s'); break;
default: sb.append('?'); break;
}
return sb.toString();
} }
} }
@@ -251,21 +214,15 @@ public class Card implements CardCodes,
* @param number the number of the card * @param number the number of the card
* @param suit the suit of the card * @param suit the suit of the card
*/ */
Card(int number, int suit) Card (int number, int suit)
{ {
this.number = number; _value = (byte)((number << 2) | suit);
this.suit = suit;
key = new Integer((number << 2) | suit);
} }
/** The number of the card. */ /** The number of the card. */
private int number; protected byte _value;
/** The suit of the card. */
private int suit;
/** The comparison key. */ /** The comparison key. */
private Integer key; protected transient Byte _key;
} }
@@ -1,5 +1,5 @@
// //
// $Id: Deck.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: Deck.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -41,7 +41,7 @@ public class Deck implements CardCodes,
* Default constructor creates an unshuffled deck of cards without * Default constructor creates an unshuffled deck of cards without
* jokers. * jokers.
*/ */
public Deck() public Deck ()
{ {
cards = new StreamableArrayList(); cards = new StreamableArrayList();
@@ -54,7 +54,7 @@ public class Deck implements CardCodes,
* @param includeJokers whether or not to include the two jokers * @param includeJokers whether or not to include the two jokers
* in the deck * in the deck
*/ */
public Deck(boolean includeJokers) public Deck (boolean includeJokers)
{ {
cards = new StreamableArrayList(); cards = new StreamableArrayList();
@@ -68,7 +68,7 @@ public class Deck implements CardCodes,
* @param includeJokers whether or not to include the two jokers * @param includeJokers whether or not to include the two jokers
* in the deck * in the deck
*/ */
public void reset(boolean includeJokers) public void reset (boolean includeJokers)
{ {
cards.clear(); cards.clear();
@@ -90,7 +90,7 @@ public class Deck implements CardCodes,
/** /**
* Shuffles the deck. * Shuffles the deck.
*/ */
public void shuffle() public void shuffle ()
{ {
Collections.shuffle(cards); Collections.shuffle(cards);
} }
@@ -102,7 +102,7 @@ public class Deck implements CardCodes,
* @return the newly created and populated hand, or null * @return the newly created and populated hand, or null
* if there are not enough cards in the deck to deal the hand * if there are not enough cards in the deck to deal the hand
*/ */
public Hand dealHand(int size) public Hand dealHand (int size)
{ {
if(cards.size() < size) if(cards.size() < size)
{ {
@@ -127,7 +127,7 @@ public class Deck implements CardCodes,
* *
* @param hand the hand of cards to return * @param hand the hand of cards to return
*/ */
public void returnHand(Hand hand) public void returnHand (Hand hand)
{ {
cards.addAll(hand.cards); cards.addAll(hand.cards);
hand.cards.clear(); hand.cards.clear();
@@ -138,7 +138,7 @@ public class Deck implements CardCodes,
* *
* @return a description of this deck * @return a description of this deck
*/ */
public String toString() public String toString ()
{ {
return "[cards=" + cards.toString() + "]"; return "[cards=" + cards.toString() + "]";
} }
@@ -1,5 +1,5 @@
// //
// $Id: Hand.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: Hand.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -21,7 +21,7 @@
package com.threerings.parlor.card.data; package com.threerings.parlor.card.data;
import java.util.*; import java.util.Iterator;
import com.threerings.io.Streamable; import com.threerings.io.Streamable;
@@ -40,7 +40,7 @@ public class Hand implements CardCodes,
/** /**
* Default constructor creates an empty hand. * Default constructor creates an empty hand.
*/ */
public Hand() public Hand ()
{ {
cards = new StreamableArrayList(); cards = new StreamableArrayList();
} }
@@ -51,7 +51,7 @@ public class Hand implements CardCodes,
* @param suit the suit of interest * @param suit the suit of interest
* @return the number of cards in the specified suit * @return the number of cards in the specified suit
*/ */
public int getSuitMemberCount(int suit) public int getSuitMemberCount (int suit)
{ {
int members = 0; int members = 0;
@@ -73,7 +73,7 @@ public class Hand implements CardCodes,
* *
* @return a description of this hand * @return a description of this hand
*/ */
public String toString() public String toString ()
{ {
return "[cards=" + cards.toString() + "]"; return "[cards=" + cards.toString() + "]";
} }
@@ -1,5 +1,5 @@
// //
// $Id: CardGameManager.java,v 1.2 2004/10/13 19:29:12 andrzej Exp $ // $Id: CardGameManager.java,v 1.3 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -48,7 +48,7 @@ public class CardGameManager extends GameManager
* @return the hand dealt to the player, or null if the deal * @return the hand dealt to the player, or null if the deal
* was canceled because the deck did not contain enough cards * was canceled because the deck did not contain enough cards
*/ */
public Hand dealHand(Deck deck, int size, int playerIndex) public Hand dealHand (Deck deck, int size, int playerIndex)
{ {
if(deck.cards.size() < size) if(deck.cards.size() < size)
{ {
@@ -80,7 +80,7 @@ public class CardGameManager extends GameManager
* the deal was canceled because the deck did not contain enough * the deal was canceled because the deck did not contain enough
* cards * cards
*/ */
public Hand[] dealHands(Deck deck, int size) public Hand[] dealHands (Deck deck, int size)
{ {
if(deck.cards.size() < size * _playerCount) if(deck.cards.size() < size * _playerCount)
{ {
@@ -1,5 +1,5 @@
// //
// $Id: TrickCardGameController.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: TrickCardGameController.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -35,7 +35,7 @@ public interface TrickCardGameController extends TurnGameController
* @param playingHand true if the gameplay entered a hand, false if * @param playingHand true if the gameplay entered a hand, false if
* it left one * it left one
*/ */
public void playingHandDidChange(boolean playingHand); public void playingHandDidChange (boolean playingHand);
/** /**
* Notifies the controller that the gameplay entered or left a trick. * Notifies the controller that the gameplay entered or left a trick.
@@ -43,5 +43,5 @@ public interface TrickCardGameController extends TurnGameController
* @param playingTrick true if the gameplay entered a trick, false if * @param playingTrick true if the gameplay entered a trick, false if
* it left one * it left one
*/ */
public void playingTrickDidChange(boolean playingTrick); public void playingTrickDidChange (boolean playingTrick);
} }
@@ -1,5 +1,5 @@
// //
// $Id: TrickCardGameControllerDelegate.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: TrickCardGameControllerDelegate.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -31,16 +31,12 @@ import com.threerings.presents.dobj.AttributeChangedEvent;
*/ */
public class TrickCardGameControllerDelegate extends TurnGameControllerDelegate public class TrickCardGameControllerDelegate extends TurnGameControllerDelegate
{ {
/** The trick card game controller. */
protected TrickCardGameController _tcgctrl;
/** /**
* Constructor. * Constructor.
* *
* @param controller the game controller * @param controller the game controller
*/ */
public TrickCardGameControllerDelegate(TrickCardGameController controller) public TrickCardGameControllerDelegate (TrickCardGameController controller)
{ {
super(controller); super(controller);
@@ -48,7 +44,7 @@ public class TrickCardGameControllerDelegate extends TurnGameControllerDelegate
} }
// Documentation inherited // Documentation inherited
public void attributeChanged(AttributeChangedEvent ace) public void attributeChanged (AttributeChangedEvent ace)
{ {
super.attributeChanged(ace); super.attributeChanged(ace);
@@ -63,4 +59,8 @@ public class TrickCardGameControllerDelegate extends TurnGameControllerDelegate
_tcgctrl.playingTrickDidChange(tcgObj.getPlayingTrick()); _tcgctrl.playingTrickDidChange(tcgObj.getPlayingTrick());
} }
} }
/** The trick card game controller. */
protected TrickCardGameController _tcgctrl;
} }
@@ -1,5 +1,5 @@
// //
// $Id: TrickCardGameManager.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: TrickCardGameManager.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -32,30 +32,30 @@ public interface TrickCardGameManager extends TurnGameManager
/** /**
* Notifies the manager that a hand is about to start. * Notifies the manager that a hand is about to start.
*/ */
public void handWillStart(); public void handWillStart ();
/** /**
* Notifies the manager that a hand just started. * Notifies the manager that a hand just started.
*/ */
public void handDidStart(); public void handDidStart ();
/** /**
* Notifies the manager that a hand has ended. * Notifies the manager that a hand has ended.
*/ */
public void handDidEnd(); public void handDidEnd ();
/** /**
* Notifies the manager that a trick is about to start. * Notifies the manager that a trick is about to start.
*/ */
public void trickWillStart(); public void trickWillStart ();
/** /**
* Notifies the manager that a trick just started. * Notifies the manager that a trick just started.
*/ */
public void trickDidStart(); public void trickDidStart ();
/** /**
* Notifies the manager that a trick has ended. * Notifies the manager that a trick has ended.
*/ */
public void trickDidEnd(); public void trickDidEnd ();
} }
@@ -1,5 +1,5 @@
// //
// $Id: TrickCardGameManagerDelegate.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: TrickCardGameManagerDelegate.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -32,20 +32,13 @@ import com.threerings.parlor.turn.TurnGameManagerDelegate;
* Spades and Hearts. * Spades and Hearts.
*/ */
public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
{ {
/** The trick card game manager. */
protected TrickCardGameManager _tcgmgr;
/** The game object. */
protected TrickCardGameObject _trickCardGame;
/** /**
* Constructor. * Constructor.
* *
* @param manager the game manager * @param manager the game manager
*/ */
public TrickCardGameManagerDelegate(TrickCardGameManager manager) public TrickCardGameManagerDelegate (TrickCardGameManager manager)
{ {
super(manager); super(manager);
@@ -53,7 +46,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
} }
// Documentation inherited. // Documentation inherited.
public void setFirstTurnHolder() public void setFirstTurnHolder ()
{ {
if(_trickCardGame.getPlayingHand() && _trickCardGame.getPlayingTrick()) if(_trickCardGame.getPlayingHand() && _trickCardGame.getPlayingTrick())
{ {
@@ -66,7 +59,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
} }
// Documentation inherited. // Documentation inherited.
public void setNextTurnHolder() public void setNextTurnHolder ()
{ {
if(_trickCardGame.getPlayingHand() && _trickCardGame.getPlayingTrick()) if(_trickCardGame.getPlayingHand() && _trickCardGame.getPlayingTrick())
{ {
@@ -79,7 +72,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
} }
// Documentation inherited. // Documentation inherited.
public void didStartup(PlaceObject plobj) public void didStartup (PlaceObject plobj)
{ {
super.didStartup(plobj); super.didStartup(plobj);
@@ -89,7 +82,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
/** /**
* Starts a hand of cards. * Starts a hand of cards.
*/ */
public void startHand() public void startHand ()
{ {
_tcgmgr.handWillStart(); _tcgmgr.handWillStart();
@@ -101,7 +94,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
/** /**
* Ends a hand of cards. * Ends a hand of cards.
*/ */
public void endHand() public void endHand ()
{ {
_trickCardGame.setPlayingHand(false); _trickCardGame.setPlayingHand(false);
@@ -111,7 +104,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
/** /**
* Starts a trick. * Starts a trick.
*/ */
public void startTrick() public void startTrick ()
{ {
_tcgmgr.trickWillStart(); _tcgmgr.trickWillStart();
@@ -123,10 +116,17 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
/** /**
* Ends a trick. * Ends a trick.
*/ */
public void endTrick() public void endTrick ()
{ {
_trickCardGame.setPlayingTrick(false); _trickCardGame.setPlayingTrick(false);
_tcgmgr.trickDidEnd(); _tcgmgr.trickDidEnd();
} }
/** The trick card game manager. */
protected TrickCardGameManager _tcgmgr;
/** The game object. */
protected TrickCardGameObject _trickCardGame;
} }
@@ -1,5 +1,5 @@
// //
// $Id: TrickCardGameObject.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: TrickCardGameObject.java,v 1.2 2004/10/15 00:14:23 andrzej Exp $
// //
// Narya library - tools for developing networked games // Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved // Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -34,21 +34,21 @@ public interface TrickCardGameObject extends TurnGameObject
* *
* @return the name of the playingHand field * @return the name of the playingHand field
*/ */
public String getPlayingHandFieldName(); public String getPlayingHandFieldName ();
/** /**
* Checks whether the users are currently playing a hand. * Checks whether the users are currently playing a hand.
* *
* @return true if the users are playing a hand, false otherwise * @return true if the users are playing a hand, false otherwise
*/ */
public boolean getPlayingHand(); public boolean getPlayingHand ();
/** /**
* Brings the gameplay in or out of a hand. * Brings the gameplay in or out of a hand.
* *
* @param playingHand true to enter a hand, false to leave one * @param playingHand true to enter a hand, false to leave one
*/ */
public void setPlayingHand(boolean playingHand); public void setPlayingHand (boolean playingHand);
/** /**
* Returns the name of the field that signals whether or not the users * Returns the name of the field that signals whether or not the users
@@ -56,19 +56,19 @@ public interface TrickCardGameObject extends TurnGameObject
* *
* @return the name of the playingTrick field * @return the name of the playingTrick field
*/ */
public String getPlayingTrickFieldName(); public String getPlayingTrickFieldName ();
/** /**
* Checks whether the users are currently playing a trick. * Checks whether the users are currently playing a trick.
* *
* @return true if the users are playing a trick, false otherwise * @return true if the users are playing a trick, false otherwise
*/ */
public boolean getPlayingTrick(); public boolean getPlayingTrick ();
/** /**
* Brings the gameplay in or out of a trick. * Brings the gameplay in or out of a trick.
* *
* @param playingTrick true to enter a trick, false to leave one * @param playingTrick true to enter a trick, false to leave one
*/ */
public void setPlayingTrick(boolean playingTrick); public void setPlayingTrick (boolean playingTrick);
} }