First checkin for the great Spades refactor.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3465 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2005-04-12 02:50:17 +00:00
parent bc30a3f389
commit 7fd9b51cab
22 changed files with 2197 additions and 497 deletions
@@ -1,54 +0,0 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.parlor.card.data;
import com.threerings.parlor.card.client.CardGameService;
import com.threerings.parlor.card.data.Card;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.dobj.InvocationResponseEvent;
/**
* Provides the implementation of the {@link CardGameService} interface
* that marshalls the arguments and delivers the request to the provider
* on the server. Also provides an implementation of the response listener
* interfaces that marshall the response arguments and deliver them back
* to the requesting client.
*/
public class CardGameMarshaller extends InvocationMarshaller
implements CardGameService
{
/** The method id used to dispatch {@link #sendCardsToPlayer} requests. */
public static final int SEND_CARDS_TO_PLAYER = 1;
// documentation inherited from interface
public void sendCardsToPlayer (Client arg1, int arg2, Card[] arg3, InvocationService.ConfirmListener arg4)
{
InvocationMarshaller.ConfirmMarshaller listener4 = new InvocationMarshaller.ConfirmMarshaller();
listener4.listener = arg4;
sendRequest(arg1, SEND_CARDS_TO_PLAYER, new Object[] {
new Integer(arg2), arg3, listener4
});
}
}
@@ -28,29 +28,4 @@ import com.threerings.parlor.game.data.GameObject;
*/
public class CardGameObject extends GameObject
{
// AUTO-GENERATED: FIELDS START
/** The field name of the <code>cardGameService</code> field. */
public static final String CARD_GAME_SERVICE = "cardGameService";
// AUTO-GENERATED: FIELDS END
/** The card game service interface. */
public CardGameMarshaller cardGameService;
// AUTO-GENERATED: METHODS START
/**
* Requests that the <code>cardGameService</code> field be set to the
* specified value. The local value will be updated immediately and an
* event will be propagated through the system to notify all listeners
* that the attribute did change. Proxied copies of this object (on
* clients) will apply the value change when they received the
* attribute changed notification.
*/
public void setCardGameService (CardGameMarshaller value)
{
CardGameMarshaller ovalue = this.cardGameService;
requestAttributeChange(
CARD_GAME_SERVICE, value, ovalue);
this.cardGameService = value;
}
// AUTO-GENERATED: METHODS END
}
@@ -23,28 +23,20 @@ package com.threerings.parlor.card.data;
import java.util.Collections;
import com.threerings.io.Streamable;
import com.threerings.util.StreamableArrayList;
/**
* Instances of this class represent decks of cards.
*/
public class Deck implements CardCodes,
Streamable
public class Deck extends StreamableArrayList
implements CardCodes
{
/** The cards in the deck. */
public StreamableArrayList cards;
/**
* Default constructor creates an unshuffled deck of cards without
* jokers.
*/
public Deck ()
{
cards = new StreamableArrayList();
reset(false);
}
@@ -56,8 +48,6 @@ public class Deck implements CardCodes,
*/
public Deck (boolean includeJokers)
{
cards = new StreamableArrayList();
reset(includeJokers);
}
@@ -70,17 +60,17 @@ public class Deck implements CardCodes,
*/
public void reset (boolean includeJokers)
{
cards.clear();
clear();
for (int i=SPADES;i<=DIAMONDS;i++) {
for (int j=2;j<=ACE;j++) {
cards.add(new Card(j, i));
for (int i = SPADES; i <= DIAMONDS; i++) {
for (int j = 2; j <= ACE; j++) {
add(new Card(j, i));
}
}
if (includeJokers) {
cards.add(new Card(RED_JOKER, 3));
cards.add(new Card(BLACK_JOKER, 3));
add(new Card(RED_JOKER, 3));
add(new Card(BLACK_JOKER, 3));
}
}
@@ -89,7 +79,7 @@ public class Deck implements CardCodes,
*/
public void shuffle ()
{
Collections.shuffle(cards);
Collections.shuffle(this);
}
/**
@@ -101,15 +91,15 @@ public class Deck implements CardCodes,
*/
public Hand dealHand (int size)
{
if (cards.size() < size) {
if (size() < size) {
return null;
}
else {
} else {
Hand hand = new Hand();
int cardsLeft = cards.size();
for (int i=0;i<size;i++) {
hand.cards.add(cards.remove(--cardsLeft));
int cardsLeft = size();
for (int i = 0; i < size; i++) {
hand.add(remove(--cardsLeft));
}
return hand;
@@ -123,17 +113,7 @@ public class Deck implements CardCodes,
*/
public void returnHand (Hand hand)
{
cards.addAll(hand.cards);
hand.cards.clear();
}
/**
* Returns a string representation of this deck.
*
* @return a description of this deck
*/
public String toString ()
{
return "[cards=" + cards.toString() + "]";
addAll(hand);
hand.clear();
}
}
@@ -1,5 +1,5 @@
//
// $Id: Hand.java,v 1.4 2004/10/15 18:20:28 andrzej Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -21,28 +21,44 @@
package com.threerings.parlor.card.data;
import java.util.Iterator;
import com.threerings.io.Streamable;
import com.threerings.util.StreamableArrayList;
/**
* Instances of this class represent hands of cards.
*/
public class Hand implements CardCodes,
Streamable
public class Hand extends StreamableArrayList
{
/** The cards in the hand. */
public StreamableArrayList cards;
/**
* Adds all of the specified cards to this hand.
*/
public void addAll (Card[] cards)
{
for (int i = 0; i < cards.length; i++) {
add(cards[i]);
}
}
/**
* Default constructor creates an empty hand.
* Removes all of the specified cards from this hand.
*/
public Hand ()
public void removeAll (Card[] cards)
{
cards = new StreamableArrayList();
for (int i = 0; i < cards.length; i++) {
remove(cards[i]);
}
}
/**
* Checks whether this hand contains all of the specified cards.
*/
public boolean containsAll (Card[] cards)
{
for (int i = 0; i < cards.length; i++) {
if (!contains(cards[i])) {
return false;
}
}
return true;
}
/**
@@ -53,26 +69,12 @@ public class Hand implements CardCodes,
*/
public int getSuitMemberCount (int suit)
{
int members = 0;
Iterator it = cards.iterator();
while (it.hasNext()) {
if (((Card)it.next()).getSuit() == suit) {
members++;
int len = size(), members = 0;
for (int i = 0; i < len; i++) {
if (((Card)get(i)).getSuit() == suit) {
members++;
}
}
return members;
}
/**
* Returns a string representation of this hand.
*
* @return a description of this hand
*/
public String toString ()
{
return "[cards=" + cards.toString() + "]";
}
}
@@ -0,0 +1,54 @@
//
// $Id: TrickCardGameObject.java 3382 2005-03-03 19:55:35Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.parlor.card.data;
import com.threerings.io.Streamable;
/**
* Pairs a player index with the card that the player played in the trick.
*/
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.
*
* @param pidx the index of the player
* @param card the card played
*/
public PlayerCard (int pidx, Card card)
{
this.pidx = pidx;
this.card = card;
}
}