Card game services.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3133 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2004-10-13 02:03:26 +00:00
parent af6409e742
commit 82cf7b0a47
15 changed files with 1534 additions and 0 deletions
@@ -0,0 +1,75 @@
//
// $Id: CardGameManager.java,v 1.1 2004/10/13 02:03:26 andrzej Exp $
//
// 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.server;
import com.threerings.parlor.card.Log;
import com.threerings.parlor.card.data.CardCodes;
import com.threerings.parlor.card.data.Deck;
import com.threerings.parlor.card.data.Hand;
import com.threerings.parlor.game.GameManager;
import com.threerings.presents.dobj.MessageEvent;
/**
* A manager class for card games. Handles common functions like dealing hands
* of cards to all players.
*/
public class CardGameManager extends GameManager
implements CardCodes
{
/**
* 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
*/
public Hand[] dealHands(Deck deck, int size)
{
if(deck.cards.size() < size * _playerCount)
{
return null;
}
else
{
Hand[] hands = new Hand[_playerCount];
for(int i=0;i<_playerCount;i++)
{
_omgr.postEvent(
new MessageEvent(
_playerOids[i],
TAKE_HAND,
new Object[] { hands[i] = deck.dealHand(size) }
)
);
}
return hands;
}
}
}