|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectks.common.model.Element
ks.common.model.Card
Representation of a Card in the model.
The valid suits for a Card are {CLUBS, DIAMONDS, HEARTS, SPADES}, and the valid ranks
are 1 (ACE) through 13 (KING). Note that the rank for ACE is lower than other cards.
There is a method boolean isAce()
that can be used to see if a Card object is an
ACE. boolean isFaceCard()
returns whether a Card object is a JACK, QUEEN, or
KING.
Once created, a Card may have several state changes: Rank, Suit, FaceUp, Selected. In each
case, the hasChanged()
method for Element is invoked after the change to
announce the change to any viewers.
The name for a Card element is determined by its value. There is no way to set the name for a card except by altering its suit and/or rank.
Field Summary | |
static int |
ACE
Specific rank value of an ACE |
static java.lang.String |
ACEabbreviation
String abbreviation of Ace. |
static int |
CLUBS
Specific suit value of Clubs |
static java.lang.String |
CLUBSabbreviation
String abbreviation of Clubs. |
static java.lang.String |
CLUBSname
String name of Clubs. |
static int |
DIAMONDS
Specific suit value of Diamonds |
static java.lang.String |
DIAMONDSabbreviation
String abbreviation of Diamonds. |
static java.lang.String |
DIAMONDSname
String name of Diamonds. |
static int |
EIGHT
Specific rank value of an Eight. |
static int |
FIVE
Specific rank value of a Five |
static int |
FOUR
Specific rank value of a Four |
static int |
HEARTS
Specific suit value of Hearts. |
static java.lang.String |
HEARTSabbreviation
String abbreviation of Hearts. |
static java.lang.String |
HEARTSname
String name of HEARTS. |
static int |
JACK
Specific rank value of a Jack |
static java.lang.String |
JACKabbreviation
String abbreviation of Jack. |
static int |
KING
Specific rank value of a King |
static java.lang.String |
KINGabbreviation
String abbreviation of King. |
static java.lang.String |
KINGstring
String representation of King. |
static int |
NINE
Specific rank value of a Nine |
static int |
QUEEN
Specific rank value of a Queen |
static java.lang.String |
QUEENabbreviation
String abbreviation of Queen. |
static char |
selectedChar
Character used in string representation to denote selected Card. |
static int |
SEVEN
Specific rank value of a Seven |
static int |
SIX
Specific rank value of a Six |
static int |
SPADES
Specific suit value of Spades. |
static java.lang.String |
SPADESabbreviation
String abbreviation of Spades. |
static java.lang.String |
SPADESname
String name of Spades. |
static int |
TEN
Specific rank value of a Ten |
static int |
THREE
Specific rank value of a Three |
static int |
TWO
Specific rank value of a Two |
Constructor Summary | |
Card(Card c)
Construct a card that is a copy of the given Card. |
|
Card(int rank,
int suit)
Construct a card with the given rank and suit. |
Method Summary | |
int |
compareTo(Card c)
Compares cards based on ranks. |
java.lang.String |
getName()
Return a string reflective of this Card. |
int |
getRank()
Return the rank for this card. |
int |
getSuit()
Return the suit for this card. |
static java.lang.String |
getSuitName(int suit)
Static method for converting a specific suit identifier into its String representation. |
boolean |
isAce()
Determine whether the card is an ACE. |
boolean |
isFaceCard()
Determine whether the Card is a Face Card (Jack, Queen, King). |
boolean |
isFaceUp()
Determine whether the Card is face up. |
boolean |
isSelected()
Determine whether the card has been selected. |
boolean |
oppositeColor(Card c)
Determines whether the two cards have opposite colors. |
boolean |
oppositeColor(int otherSuit)
Determines whether the Card has an opposite color than the given suit. |
boolean |
sameColor(Card c)
Determine whether the two cards have the same color. |
boolean |
sameColor(int otherSuit)
Determines whether the Card has the same color as the given suit. |
boolean |
sameRank(Card c)
Determine whether two cards have the same rank. |
boolean |
sameSuit(Card c)
Determine whether the two cards have the same suit. |
void |
setFaceUp(boolean newFaceUp)
Set the faceUp value of this card. |
void |
setName(java.lang.String s)
Deny any request to change the name of a card. |
void |
setRank(int newRank)
Set the rank value of this card. |
void |
setSelected(boolean newSelected)
Set the selected status of this card. |
void |
setSuit(int newSuit)
Set the suit value of this card. |
java.lang.String |
toString()
Return a string reflective of this Card. |
static java.lang.String |
toString(int rank,
int suit)
Static method for converting a specific rank/suit into its String representation. |
Methods inherited from class ks.common.model.Element |
getListener, setListener |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int ACE
public static final int TWO
public static final int THREE
public static final int FOUR
public static final int FIVE
public static final int SIX
public static final int SEVEN
public static final int EIGHT
public static final int NINE
public static final int TEN
public static final int JACK
public static final int QUEEN
public static final int KING
public static final int CLUBS
public static final int DIAMONDS
public static final int HEARTS
public static final int SPADES
public static final java.lang.String ACEabbreviation
public static final java.lang.String KINGstring
public static final java.lang.String KINGabbreviation
public static final java.lang.String QUEENabbreviation
public static final java.lang.String JACKabbreviation
public static final java.lang.String CLUBSabbreviation
public static final java.lang.String CLUBSname
public static final java.lang.String DIAMONDSabbreviation
public static final java.lang.String DIAMONDSname
public static final java.lang.String HEARTSabbreviation
public static final java.lang.String HEARTSname
public static final java.lang.String SPADESabbreviation
public static final java.lang.String SPADESname
public static final char selectedChar
Constructor Detail |
public Card(int rank, int suit)
By default, the card is face up and not selected. Since v1.7, the name is calculated on
demand in getName()
, overridden by this class
java.lang.IllegalArgumentException
- if rank or suit is an invalid value.public Card(Card c)
This includes faceup and selected Information (since V1.5.1). Since v1.7, the name is
calculated on demand by getName()
, overriden by this class.
c
- ks.common.model.CardMethod Detail |
public int compareTo(Card c)
If c is a null card, then Integer.MAX_VALUE is returned.
c
- ks.common.model.Card
public java.lang.String getName()
This method overrides getName()
method in Element.
getName
in class Element
public int getRank()
public int getSuit()
public boolean isAce()
public boolean isFaceCard()
public boolean isFaceUp()
public boolean isSelected()
public boolean oppositeColor(int otherSuit)
If suit is not a valid suit, then an IllegalArgumentException is thrown.
otherSuit
- suit to which we are being compared.
public boolean oppositeColor(Card c)
c
- ks.common.model.Card
public boolean sameColor(Card c)
c
- ks.common.model.Card
public boolean sameColor(int otherSuit)
otherSuit
- other suit to which we are being compared.
public boolean sameRank(Card c)
If the card passed in is null, then false is returned.
c
- ks.common.model.Card
public boolean sameSuit(Card c)
If the card passed in is null, then false is returned.
c
- ks.common.model.Card
public void setFaceUp(boolean newFaceUp)
Generates modelChanged action if new faceUp status is different from old.
newFaceUp
- booleanpublic void setName(java.lang.String s)
This is here because we override the setName()
method of Element.
setName
in class Element
s
- proposed new name.public void setRank(int newRank)
Generates modelChanged action if new rank is different from old rank.
newRank
- intpublic void setSelected(boolean newSelected)
Generates modelChanged action if new selected state is different from old selected state.
newSelected
- booleanpublic void setSuit(int newSuit)
Generates modelChanged action if new suit is different from old suit.
newSuit
- intpublic java.lang.String toString()
Creation date: (10/1/01 8:50:08 PM)
toString
in class Element
public static java.lang.String getSuitName(int suit)
suit
- int
public static java.lang.String toString(int rank, int suit)
rank
- intsuit
- int
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |