Background Information Our WAR game variation There are two
Background Information:
Our WAR game variation:
There are two players playing the game. Each of the players are dealt a set of cards (with equal
number of cards) from a shuffled deck of cards. When the game starts, the players open up the
top card. The open cards are compared to see which one is higher. In the comparison, the King
card is the highest while the Ace card is the lowest.
In the event of a tie, the suit of the card will determine the winner of the match. The suits are
ranked as follows (from the highest suit rank): Spades, Hearts, Diamonds, Clubs. The suit with
the higher rank wins. The winner of the match gets a point. Note that there will always be a
winner in a match.
The game continues until all the player cards have been played and the player with the higher
score wins the war.
Developing the Game
Before the game can be developed, a number of required classes need to be developed.
1. The Card Class
The Card class should describe a specific card, ie., the Ace of Spaces. It should have the
usual getters and setters and any addditional methods that will be needed to determine the
outcome of the card match.
2. The CardDeck Class
The CardDeck class contains the standard deck of 52 cards (4 suits with each suit
containing 13 different ranks of cards). To hold the cards, you must use a generic
DoublyLinkedList structure.
Use this class to initally populate the deck with the 52 cards (much like opening a new
deck). In addition, you can also use this class for the shuffled deck of cards that will be
used in the game.
3. The Shuffler Class
This class is used to shuffle a deck of cards. You will need to use this class before the
game can be started.
You may want to research how to shuffle a deck of cards, using Java. The details of how
the deck is shuffled is left to you. However, what is important here is that the deck of
cards are shuffled and that the results of each shuffle are different.
4. The LinkedList Implementation of the Stack class
For the Stack class you must use the LinkedList Implementation of the Stack structure.
This development is a major component of this assignment. You must create a
StackInterface class as well.
5. The WarGame Class (which is the main processor class)
This is the processor class that actually plays the game. It starts off with getting a deck of
cards, shuffling the deck, and dealing the cards to the players. The number of cards that
the players get is determined by the user of your game.
Once the cards are dealt, then the game begins and scoring is done using the game
description above.
For the game, the shuffled deck, and the cards that the players have, are implemented
using the LinkedListStack.
Program Development:
1. You may want to start with the shuffling algorithm. Rather than shuffle a deck of cards,
test your shuffle algorithm by shuffling 10 numbers and see if your shuffler works. Once
this works, it can easily be expanded to 52 cards which can be done later.
2. Next, develop the Card class. This is a relatively simple class and should not take too
long.
3. Once the Card class is developed, develop the CardDeck class. Work on how you will
initially populate the deck of cards.
4. Once you are satisfied with the CardDeck class, develop the Shuffler class using the
shuffling algorithm in #1 but expanding it to accommodate a full deck of cards. Once
finished, you can now shuffle any deck of cards.
5. Once done, you now have the basic requirements to start working on the game itself.
There are a number of approaches to completing this.
a. One approach is to develop the Stack class first, using the class discussions as the
guide in the development. Once this is developed, the WarGame class can now
be developed and tested.
b. A second approach is to develop the WarGame class by using the Java Stack class
as the Stack structure. It is true that you cannot submit your assignment with this
class but nothing prevents you from using it to help in the development. Once
you are satisfied with the WarGame class, you can now concentrate on
developing your own Stack class. Then, modify the WarGame class to reflect the
fact that you will now use the Stack class you developed.
As before, incremental development is the way to handle large development projects.
Testing the Game
As suggested, the system should be thoroughly tested. To do this, test each class as it is being
developed. You may create a number of test clients to do the testing.
Solution
When most of use began programming, we started looking for various project ideas to try. I\'ve noticed card games come up a lot, so let\'s have a look at some ways to implement a card game. We will be focusing on the core of many card games, the cards and the deck.
The Card class is fairly simple, although it can be done a number of ways. I\'ve chosen to use numeric variables for the internal data about the suit and rank, which will get converted to strings via predefined arrays when they need to be outputed. This lets us easily compare the suits and ranks (see if they\'re equal or sequential), without trying to use strings to represent them internally. If we used strings, we\'d have to use
if ( card1.rank.equals(\"three\") && card2.rank.equals(\"four\") )
package javacards;
public class Card
{
private int rank, suit;
private static String[] suits = { \"hearts\", \"spades\", \"diamonds\", \"clubs\" };
private static String[] ranks = { \"Ace\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"Jack\", \"Queen\", \"King\" };
Card(int suit, int rank)
{
this.rank=rank;
this.suit=suit;
}
public @Override String toString()
{
return ranks[rank] + \" of \" + suits[suit];
}
public int getRank() {
return rank;
}
public int getSuit() {
return suit;
}
}