Samstag, 4. Oktober 2008

Java Hearts Remarks4

EE3206/EE5805 Java Programming and Application

Java Hearts Game Project Remarks4

The following notes are summarized from David Eck 's Introduction to Programming Using Java, Chap 5.4:

http://math.hws.edu/javanotes/index.html


1. For the Hearts Game, we need a standard deck of playing cards. Each player gets a hand of cards.

2. The Deck is shuffled and Cards are dealt one at a time from the Deck and added to the player's hand.

3. The Card classs has instance variable, suit and value.

4.The Deck class has shuffle() and dealCard().

5. The Hand class has addCard() and removeCard()

6. A Deck obect has 52 cards in standard order when created. Activate shuffle() to randomize the card.

Activate dealCard() to get the next card from the deck. The return type is card.


7.Hand Class. It has no cards when first created. Activate addCard() to add a card to the hand.

Specify the Card object for which card is added. Activate removeCard() to specify which card to remove.


8. Card Class. Use new Card(value, suit) to create a card object. There are four suits, eg, Card.SPADES.
Use enum type to specify.

In the Hearts game, Ace is the largest while 2 is the smallest card. Modify the code.

9. In text mode, 2 helper methods, getValueAsString() and getSuitAsString() for toString() .

Keine Kommentare: