Added isValid() method to Card, ability to deal single hands to CardGameManager.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3135 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2004-10-13 19:29:12 +00:00
parent 90af7c794d
commit 9bbd46fa7b
4 changed files with 53 additions and 14 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# $Id: genreceiver,v 1.3 2002/08/20 19:36:43 mdb Exp $ # $Id: genreceiver,v 1.4 2004/10/13 19:29:12 andrzej Exp $
# #
# This script is used to generate invocation receiver marshaller and # This script is used to generate invocation receiver marshaller and
# unmarshaller classes based on receiver interface definitions. # unmarshaller classes based on receiver interface definitions.
@@ -72,7 +72,7 @@ while ($srcfile = shift) {
# run javap on the interface class # run javap on the interface class
my $jpcp = (defined $classpath) ? "-classpath $classpath" : ""; my $jpcp = (defined $classpath) ? "-classpath $classpath" : "";
my $jpcmd = "javap $jpcp $class"; my $jpcmd = "/usr/local/j2sdk1.4.1/bin/javap $jpcp $class";
# clear out the imports table # clear out the imports table
%imports = (); %imports = ();
+2 -2
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
# #
# $Id: genservice,v 1.5 2002/08/20 19:36:43 mdb Exp $ # $Id: genservice,v 1.6 2004/10/13 19:29:12 andrzej Exp $
# #
# This script is used to generate invocation service marshaller and # This script is used to generate invocation service marshaller and
# unmarshaller classes based on invocation service interface definitions. # unmarshaller classes based on invocation service interface definitions.
@@ -72,7 +72,7 @@ while ($srcfile = shift) {
# run javap on the interface class # run javap on the interface class
my $jpcp = (defined $classpath) ? "-classpath $classpath" : ""; my $jpcp = (defined $classpath) ? "-classpath $classpath" : "";
my $jpcmd = "javap $jpcp $class"; my $jpcmd = "/usr/local/j2sdk1.4.1/bin/javap $jpcp $class";
# clear out the imports table # clear out the imports table
%imports = (); %imports = ();
@@ -1,5 +1,5 @@
// //
// $Id: Card.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: Card.java,v 1.2 2004/10/13 19:29:12 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
@@ -70,7 +70,7 @@ public class Card implements CardCodes,
*/ */
public boolean isNumber() public boolean isNumber()
{ {
return number <= 11; return number >= 2 && number <= 10;
} }
/** /**
@@ -103,6 +103,19 @@ public class Card implements CardCodes,
return number == JOKER; return number == JOKER;
} }
/**
* 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()
{
return number == JOKER ||
(number >= 2 && number <= ACE &&
suit >= HEARTS && suit <= SPADES);
}
/** /**
* Writes this object to the specified output stream. * Writes this object to the specified output stream.
* *
@@ -1,5 +1,5 @@
// //
// $Id: CardGameManager.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $ // $Id: CardGameManager.java,v 1.2 2004/10/13 19:29:12 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,6 +38,38 @@ import com.threerings.presents.dobj.MessageEvent;
public class CardGameManager extends GameManager public class CardGameManager extends GameManager
implements CardCodes implements CardCodes
{ {
/**
* 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
*/
public Hand dealHand(Deck deck, int size, int playerIndex)
{
if(deck.cards.size() < size)
{
return null;
}
else
{
Hand hand = deck.dealHand(size);
_omgr.postEvent(
new MessageEvent(
_playerOids[playerIndex],
TAKE_HAND,
new Object[] { hand }
)
);
return hand;
}
}
/** /**
* Deals a hand of cards to each player from the specified * Deals a hand of cards to each player from the specified
* Deck. * Deck.
@@ -60,13 +92,7 @@ public class CardGameManager extends GameManager
for(int i=0;i<_playerCount;i++) for(int i=0;i<_playerCount;i++)
{ {
_omgr.postEvent( hands[i] = dealHand(deck, size, i);
new MessageEvent(
_playerOids[i],
TAKE_HAND,
new Object[] { hands[i] = deck.dealHand(size) }
)
);
} }
return hands; return hands;