org.jogre.common.games
Class Deck

java.lang.Object
  extended byorg.jogre.common.comm.CommGameMessage
      extended byorg.jogre.common.comm.CommTableMessage
          extended byorg.jogre.common.games.Deck
All Implemented Interfaces:
ITransmittable

public class Deck
extends CommTableMessage

Author:
GarrettL

Field Summary
static String XML_ATT_POSITION
           
static String XML_NAME
           
 
Fields inherited from class org.jogre.common.comm.CommTableMessage
NO_TABLE, tableNum, XML_ATT_TABLE_NUM
 
Fields inherited from class org.jogre.common.comm.CommGameMessage
status, username, usernameTo, XML_ATT_STATUS, XML_ATT_USERNAME, XML_ATT_USERNAME_TO
 
Constructor Summary
Deck()
          Default constructor
Deck(XMLElement message)
          Contructor that takes a xml message
 
Method Summary
 boolean addCard(Card card)
          Adds card to deck.
 int cardsLeft()
          Gets number of cards left in deck.
 Card deal()
          Dealing a card removes a card off the top of the deck.
 XMLElement flatten()
          Flatten this object.
 Card get(int index)
          Get card from deck by index
 Vector getCards()
          Getter for getting all the cards in the deck.
 void loadStandardDeck()
          Adds the standard 52 cards to the deck.
 void shuffle()
          Shuffles the deck one time.
 int size()
          Gets the number of cards in the deck.
 void sort()
          Sorts the deck by suit, then by card order value.
 String toString()
          A string representation of the deck of cards.
 
Methods inherited from class org.jogre.common.comm.CommTableMessage
flatten, getTableNum, setTableNum
 
Methods inherited from class org.jogre.common.comm.CommGameMessage
getStatus, getUsername, getUsernameTo, isUsernameSet, isUsernameToSet, setUsername, setUsernameTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

XML_NAME

public static final String XML_NAME
See Also:
Constant Field Values

XML_ATT_POSITION

public static final String XML_ATT_POSITION
See Also:
Constant Field Values
Constructor Detail

Deck

public Deck()
Default constructor


Deck

public Deck(XMLElement message)
Contructor that takes a xml message

Parameters:
message -
Throws:
TransmissionException
Method Detail

getCards

public Vector getCards()
Getter for getting all the cards in the deck.

Returns:
the cards in the deck

deal

public Card deal()
Dealing a card removes a card off the top of the deck.

Returns:
a card from the top of the deck.

get

public Card get(int index)
Get card from deck by index

Parameters:
index - Index in deck
Returns:
a card from the specified index

shuffle

public void shuffle()
Shuffles the deck one time.


cardsLeft

public int cardsLeft()
Gets number of cards left in deck.

Returns:
number of cards left in deck

addCard

public boolean addCard(Card card)
Adds card to deck.

Parameters:
card - Card
Returns:
a boolean if the card was added or not

size

public int size()
Gets the number of cards in the deck.

Returns:
the number of cards in the deck

loadStandardDeck

public void loadStandardDeck()
Adds the standard 52 cards to the deck. This may be called several times if a deck needs to have more than 52 cards in the deck.


sort

public void sort()
Sorts the deck by suit, then by card order value. H, C, D, S then 2, 3, 4 ... Q, K, A.


toString

public String toString()
A string representation of the deck of cards. For debug purposes only.

Overrides:
toString in class CommGameMessage
See Also:
Object.toString()

flatten

public XMLElement flatten()
Flatten this object.

Returns:
XML version of the state of an object which can be constructed again.
See Also:
ITransmittable.flatten()