Card Game – Part 2 – Java Program
** indicates a new item
You need these enumerations. The enums must be in their own files with names that match their type names.
· Suit
· FaceValue
Note: Java enums are different that C++ enums. They are lists of objects rather than lists of integers. The objects can have members and methods. See http://download.oracle.com/javase/tutorial/java/javaOO/enum.html for an example.
You need these classes:
· Card
o Suit
o FaceValue
o Display()
· Deck
o Shuffle()
o Deck() – constructor should initialize an ArrayList<Card> to contain 52 cards with the proper Suits and FaceValues
§ See syntax for looping through the values in an enum at http://stackoverflow.com/questions/1104975/for-loop-to-interate-over-enum-in-java
o showCards - show all of the cards
· Hand
o List of Cards
· Player
o Name
o Hand
o **move() – returns a list of cards that the user wants to play on this turn. The list may contain a single card for games like War or Spades, the list may contain multiple cards for games such as Poker. The list may be empty in the case that the user “Passes” or folds.
· **Optional AI Player – Inherits from player. This player makes a move automatically. May not be an “intelligent” move. Two reasons to do this: First some games like Black Jack have a player, the dealer, which has to follow specific rules. Second, it will make your game much easier to test if you do not have to enter the moves for the players.
· CardGame
o List of Players – players will be used in a later assignment
o Deck
o CardGame(number of players)
§ Initialize the list of players
§ Create a new deck
§ Shuffle the deck
o showDeck()
o **playRound() - should contain the game logic, a loop that continues until the game is over. This should repeatedly call the players’ move methods.
o
**deal() – called from playRound
if appropriate, should move cards from the deck to the player’s hands
o **isGameOver() – returns a boolean
o **getGameName() – returns a string with the name of the game (i.e. spades, hearts)
o **displayGameWinner() – should report the winner in some way
o ** displayRoundWinner() - should report the winner in some way
o ** cardGame.displayGameRecord() – should display each player and how many games they have one
· **Your Card Game Class – Should inherit from Card Game and override appropriate methods
Select your own
card game to implement. I encourage you
to pick a simple game that fits well with this class structure.
I recommend:
· WAR - http://www.activityvillage.co.uk/war_card_game.htm
· Go Fish - http://www.activityvillage.co.uk/go_fish.htm
· Old Maid - http://www.activityvillage.co.uk/old_maid.htm
· Others can be found at http://www.activityvillage.co.uk/card_games_for_kids.htm
Your main program
should look something like this.
public class Main {
public
static void main(String[] args) {
//get the number of
players for your game if the number veries
int numberOfPlayers = 2;
CardGame cardGame = new YourCardGame(numberOfPlayers);
System.out.println("Get
Ready to play " + cardGame.getGameName());
while(!cardGame.isGameOver())
{
cardGame.playRound();
cardGame.displayRoundWinner();
cardGame.displayGameRecord();
}
cardGame.displayGameWinner();
}
}