m3g10
Class CardDeck

java.lang.Object
  extended by m3g10.CardDeck

public class CardDeck
extends java.lang.Object

Manages cards in a deck.

Author:
Claus Hoefele
See Also:
Card

Field Summary
private  java.util.Vector cards
          The cards.
private  Card currentCard
          Currently selected card.
private  int state
          Current game state.
private static int STATE_LOST
          State LOST.
private static int STATE_MATCH
          State MATCH.
private static int STATE_NO_MATCH
          State NO_MATCH.
private static int STATE_ONE_CARD
          State ONE_CARD.
private static int STATE_START
          State START.
private static int STATE_WON
          State WON.
 
Constructor Summary
CardDeck()
           
 
Method Summary
 void add(Card card)
          Adds a card to the deck.
 boolean allCardsMatched()
          Checks whether all cards were matched.
 void closeAll()
          Closes all cards except for cards that were successfully matched.
private  Card findCard(int keyCode)
          Finds the card with the given key code.
 Card getCurrentCard()
          Getter for current card.
 int getNumberOfCards()
          Getter for number of cards.
 boolean hasLost()
          Returns true if player has lost.
 boolean hasWon()
          Returns true if player has won.
private  void init()
          Initializes cards by closing them and setting the match flag to false.
 void process(int keyCode)
          Main loop which advances the game state.
private  void shuffle()
          Assigns cards a random place and closes them.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cards

private java.util.Vector cards
The cards.


currentCard

private Card currentCard
Currently selected card.


STATE_START

private static final int STATE_START
State START.

See Also:
Constant Field Values

STATE_ONE_CARD

private static final int STATE_ONE_CARD
State ONE_CARD.

See Also:
Constant Field Values

STATE_MATCH

private static final int STATE_MATCH
State MATCH.

See Also:
Constant Field Values

STATE_NO_MATCH

private static final int STATE_NO_MATCH
State NO_MATCH.

See Also:
Constant Field Values

STATE_LOST

private static final int STATE_LOST
State LOST.

See Also:
Constant Field Values

STATE_WON

private static final int STATE_WON
State WON.

See Also:
Constant Field Values

state

private int state
Current game state.

Constructor Detail

CardDeck

public CardDeck()
Method Detail

add

public void add(Card card)
Adds a card to the deck.

Parameters:
card - new card.

process

public void process(int keyCode)
Main loop which advances the game state.

Parameters:
keyCode - selected key code.

shuffle

private void shuffle()
Assigns cards a random place and closes them.


init

private void init()
Initializes cards by closing them and setting the match flag to false.


closeAll

public void closeAll()
Closes all cards except for cards that were successfully matched.


allCardsMatched

public boolean allCardsMatched()
Checks whether all cards were matched.

Returns:
true if all cards were matched.

findCard

private Card findCard(int keyCode)
Finds the card with the given key code.

Parameters:
keyCode - key code to match.
Returns:
matching card or null if not found.

getNumberOfCards

public int getNumberOfCards()
Getter for number of cards.

Returns:
number.

getCurrentCard

public Card getCurrentCard()
Getter for current card.

Returns:
current card.

hasWon

public boolean hasWon()
Returns true if player has won.

Returns:
state.

hasLost

public boolean hasLost()
Returns true if player has lost.

Returns:
state.