Homework 8 - GUIs - part one of a card game utility
Reading: Java by Dissection, Chapters 8 and 9
Due Tuesday March 4th, at 10pm.
Program Description - A card table display
In this assigment and the next two you will create a program that lets four players play a card game
over the internet. For this basic utility, it knows almost nothing about the game. It is a utility that
could be used with any number of games. It works for any game that fits the following descrption:
- There are four players.
- A standard deck of 52 cards is used.
- The cards are shuffled and dealt to the players (13 cards to each player).
- A turn involves each player exposing one card from their hand.
- The exposed set of four cards from a turn are somehow removed from play.
Your utility will:
- Shuffle the cards.
- Deal 13 cards to each player.
- Display the local player's hand to the player.
- Display one card for each player appropriate.
- Provide for removal of the four cards displayed (one per player).
For this first part of the three part assigment, you are to create a graphical user interface (GUI) using
Java's swing API that does the following:
- Has a button or similar device to trigger the shuffle and deal of the cards. It must be
possible to play many hands. That is shuffle&deal, play some cards, clear the table, play some cards
, continuing playing cards until hand is exhausted or a new deal is performed, then repeat.
- Provide a mouse driven mechanism to trigger the selection and exposing of one card
from each player's hand. That is, one action will cause one hand to expose one card. To get all four
players to have a card showing on the table will require four separate actions. This could be one
button per player or one button that just rotates to the next player. I need not be an actual JButton,
although that is a fine choice.
- Provide a mouse driven mechanism for removing the exposed cards from the "table".
The cards must be displayed with graphical images similar to the ones found at
http://www.waste.org/~oxymoron/cards/. I suggest you
just use those but you are welcome to use others if you prefer. Whatever you use must be easily recognizable
as the cards from a conventional pack of 52 cards comprised of 13 ranks (ace through king) and 4 suits
(clubs, diamonds, hearts, and spades).
A number of aspects are intentially unspecified, leaving you freedom to make your own choices.
For example, what happens if you indicate for a player to play a card and they have already played one?
You could simply play another one, or you could give some warning that the player had already played.
For this part of the project, card selection is arbitray. For example, it is perfectly fine to just
chose the "next" card in the hand. It is important that once a card has been played, that player cannot
play that card again (until possibly after a new deal). That is, playing a card removes it from the
player's hand.
Getting Started
To help you get started I am providing five files.
- ImagePainter.java is an example I created some time ago that shows how
to load and display a GIF image.
- GIFImage.java is a file that will load GIF image. It is just the main
method out of ImagePainter.java, which waits for the image to be loaded. It does not display it.
- CardHolder.java is a minor extension of ImagePainter that adds the
ability to change the image being displayed.
- CardTest.java is a simple demo/test of the above files for displaying some cards.
- CardImages.java is class that loads a set of GIF images into
an interal array and then can provide a specific image given an instance of the class Card from
Java by Dissection chapter 6 (see below).
To run CardTest you will need to have download the card images from
http://www.waste.org/~oxymoron/cards/ and place them
in a subdirectory named "cards" in the same directory as the Java files.
You may also find the classes Deck, Card, Rank, and Suit from Java by Dissection chapter 6 useful. Those files
can be found at:
http://www.soe.ucsc.edu/~charlie/java/jbd/code/chap6/
What to turn in
This program, if done properly, will consist of a rather large number of files.
To allow for ease in grading please do the following:
- Name the class containing main() CardGame.
- Create a jar file containing all of your source files and your card images directory. Assuming
your card images are in a subdirectory "cards" in the same directory as your source files, then
you would create the jar file with:
jar cf cardgame.jar *.java cards
- Be sure and name the jar file, cardgame.jar.
Your program will be tested with the following sequence. It is strongly advised that you
make a copy of your jar file in an otherwise empty directory and try this before submmitting it.
jar xf cardgame.jar
javac *.java
java CardGame
Programs that do not compile and produce some GUI in response to the above will receive a 0 and
not be looked at further.
- Submit the jar file.
Design/Correctness Points
It is important for this assignment that you achieve a clean design for this assignment. You
are strongly encouraged to create at least an informal design using something like CRC cards or a
UML class diagram before implementing much if any code.
20 points - well designed classes
20 - shows four cards on the table and can have the card images change
10 - allows for the cards to be cleared from the table
10 - shuffles and deals the cards to 4 players at least once
10 - can reshuffle and redeal
5 - miscellaneous