Class GameCard

java.lang.Object
  extended by Card
      extended by GameCard

public class GameCard
extends Card

Represents a playing card that can be either face up or face down. The playing card has a face value, a suit, and a suit color (red or black), Bugs: none known


Field Summary
static boolean BLACK
          Represents the suit color black (for clubs and spades).
static boolean RED
          Represents the suit color red (for diamonds and hearts).
 
Fields inherited from class Card
CLUBS, DIAMONDS, HEARTS, SPADES
 
Constructor Summary
GameCard(Card card, boolean faceUp)
          Constructs a GameCard object with the same face value and suit value as the Card object given.
GameCard(int face, int suit, boolean faceUp)
          Constructs a GameCard object with the given face value and suit value.
 
Method Summary
 void flip()
          Flips the card, either from face up to face down or vice versa.
 boolean getSuitColor()
          Returns the suit color of the card.
 boolean isFaceUp()
          Returns true if the card is face up and false otherwise.
 boolean match(GameCard otherCard)
          Returns true if this card matches the given card and false otherwise.
 java.lang.String toString()
          Returns a String representing the game card.
 
Methods inherited from class Card
getFace, getSuit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RED

public static final boolean RED
Represents the suit color red (for diamonds and hearts).

See Also:
Constant Field Values

BLACK

public static final boolean BLACK
Represents the suit color black (for clubs and spades).

See Also:
Constant Field Values
Constructor Detail

GameCard

public GameCard(int face,
                int suit,
                boolean faceUp)
Constructs a GameCard object with the given face value and suit value. The card is face up if the value of faceUp is true and face down otherwise. The face value of the card is set to 1 if an invalid face value is given; the suit of the card is set to HEARTS if an invalid suit is given.

Parameters:
face - the face value of the card
suit - the suit of the card
faceUp - a boolean indicating if the card is face up

GameCard

public GameCard(Card card,
                boolean faceUp)
Constructs a GameCard object with the same face value and suit value as the Card object given. The game card is face up if the value of faceUp is true and face down otherwise.

Parameters:
card - the card whose face value and suit value to copy
faceUp - a boolean indicating if the card is face up
Method Detail

getSuitColor

public boolean getSuitColor()
Returns the suit color of the card.

Returns:
suit color (either GameCard.RED or GameCard.BLACK)

isFaceUp

public boolean isFaceUp()
Returns true if the card is face up and false otherwise.

Returns:
is the card face up?

flip

public void flip()
Flips the card, either from face up to face down or vice versa.


match

public boolean match(GameCard otherCard)
Returns true if this card matches the given card and false otherwise. Two cards match if they have the same face value and the same suit color.

Parameters:
otherCard - the card to compare
Returns:
true if the cards match, false otherwise

toString

public java.lang.String toString()
Returns a String representing the game card. If the card is face up, the string contains the face value and suit; if the card is face down, the string is "XXX".

Overrides:
toString in class Card
Returns:
string representation of the game card