de.kosi.model.game
Class Trick

java.lang.Object
  |
  +--de.kosi.model.game.Trick
All Implemented Interfaces:
java.io.Serializable

public class Trick
extends java.lang.Object
implements java.io.Serializable

This class implements a trick in a game of Bridge.

ChangeLog:

 $Log: Trick.java,v $
 Revision 1.4  2001/06/27 11:53:21  betacarotine
 Worked on the Rubber and added comments.

 Revision 1.3  2001/06/15 12:06:10  betacarotine
 added serial version UIDs to Trick and CardList.

 Revision 1.2  2001/06/15 11:35:07  betacarotine
 added serialization support to the Trick

 Revision 1.1  2001/06/15 09:33:27  betacarotine
 Changed the Game-interface. Instead of
 	int getLatestLeader()   and
 	List getLatestTrick()
 we now have
 	Trick getLatestTrick()

 The internal representation and storage of the tricks is reimplemented too
 based on the new Trick-class.


 

Version:
$Revision: 1.4 $ ($Date: 2001/06/27 11:53:21 $)
Author:
PG KoSI, Fachbereich Informatik, Universitaet Oldenburg
See Also:
Serialized Form

Field Summary
static long serialVersionUID
          Serial version id.
 
Constructor Summary
Trick(int leader, Card card, int number)
          Creates a new trick instance.
 
Method Summary
 void addCard(Card card, CardList cardList)
          Adds a card to the current trick.
 int getActivePlayer()
          Returns the direction of the active player.
 Card getCard(int direction)
          Returns the card played from the given direction.
 int getLeader()
          Returns the direction of the leader of the trick.
 int getNumber()
          Returns the number of the trick.
 int getNumberOfCards()
          Returns the number of cards currently played in this trick.
 int getSuitToFollow()
          Returns the suit to follow in the trick which is the suit of the first played card.
 int getWinner(SuitContract contract)
          Returns the direction of the winner of the trick.
 boolean isComplete()
          Returns true, if this trick is complete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
Serial version id.
Constructor Detail

Trick

public Trick(int leader,
             Card card,
             int number)
Creates a new trick instance. The cards are not given as parameters because they are not known at the "birth" of the trick.
Parameters:
leader - The leader of the trick.
card - The card played by the leader;
number - The number of the trick.
Method Detail

addCard

public void addCard(Card card,
                    CardList cardList)
             throws TrickException,
                    InvalidCardException
Adds a card to the current trick.
Parameters:
card - The card to be added to the trick.
cardList - The list of cards which must contain the given card.
Throws:
TrickException - If the trick is already complete.
InvalidCardException - If the the given list of cards does contain the given card or if the player has to follow suit.

getCard

public Card getCard(int direction)
Returns the card played from the given direction.
Parameters:
direction - The direction you want to know the played card for.
Returns:
The card played from the given direction.

getLeader

public int getLeader()
Returns the direction of the leader of the trick. The leader is the player who plays the first card in a trick.
Returns:
The direction of the leader of the trick.

getNumber

public int getNumber()
Returns the number of the trick.
Returns:
The number of the trick in a game of bridge.

getSuitToFollow

public int getSuitToFollow()
Returns the suit to follow in the trick which is the suit of the first played card.
Returns:
The suit to follow in the trick.

isComplete

public boolean isComplete()
Returns true, if this trick is complete. False otherwise.
Returns:
True, if this trick is complete. False otherwise.

getNumberOfCards

public int getNumberOfCards()
Returns the number of cards currently played in this trick.
Returns:
The number of cards currently played in this trick.

getActivePlayer

public int getActivePlayer()
                    throws TrickException
Returns the direction of the active player.
Returns:
The direction of the active player.
Throws:
TrickException - If the trick is complete.

getWinner

public int getWinner(SuitContract contract)
              throws TrickException
Returns the direction of the winner of the trick.
Parameters:
contract - The contract of the current game.
Returns:
The direction of the winner of the trick.
Throws:
TrickException - If the trick is not complete so far.