Due Date: Tuesday, June 18
Files to be submitted:
Deck.java, Solitaire.java
Required starter file:
Card.java
Sample driver programs:
TestDeck.java,
Crazy8s.java
Sample output:
SampleOutput.html
Summary
Create a class (Deck) to represent a deck of cards, and a program to play a game of solitaire.I have provided you with two programs you can run to test your Deck class. One is a testing program, and the other is a game. The latter might be be helpful for you when you're programming your game.
In this assignment you are to create a class for a deck of cards. Download the starter files (linked above). Create a new class named Deck in the project. Also create a new main class named Solitaire. These last files are the only ones that you'll be editing for this assignment.
I have provided you with a class Card that represents a single playing card.
Do not modify this class. It performs exactly the way I want it to.It contains several constants and two Lists that will be helpful to you:
Card aceOfClubs = new Card(ACE, CLUBS);creates the ace of clubs. And, of course, you can use variables in the constructor. So if r = 3 and s = DIAMONDS then
Card card = new Card(r, s);creates the 3 of diamonds.
Your first task in this assignment is to create the Deck class. It represents a deck of cards using a List instance variable. The class implements the following methods and constructors:
It's here that the Lists SUITS and RANKS can be useful.The majority of the others can be done in a single line.
Remember to start with stubs for all the methods above. Once you have all the stubs written, compile and run the test program and the card game. The results will look odd, but will start to fill out as you fill in the proper method definitions.
I have provided two driver programs for you. The first one (TestDeck)is a simple testing program. It runs thru some tests of your deck and gives you a simple PASS/FAIL result for each. It's the program you want to start with.
The second driver (Crazy8s) plays a variety of the Crazy Eights card game. It deals out the cards and lets you play with three computer players. The object of the game is to get rid of all your cards by playing them on the centre discard pile. However, you can only play a card that matches the suit or rank of the top card on the pile -- except you may play an 8 at any time.
In this version of the game you do not get to "name" the new suit when you play an eight. Instead the next player must match the suit of the eight that you played (or play an eight of their own).If you can't play, you must draw cards until you can play. If you play a two, the next player must pick up two cards. If you play a jack, the next player misses their turn. Other cards have no effect.
Lastly, you need to create the game described in the notes/slides for Lists and Streams. It is a single-player game (and so called "Solitaire"). It requires you to create and shuffle a deck, then deal cards one at a time into another List. Whenever there are four or more cards in the list, compare the last card added with the card three further back:
For example, if the four latest cards are KD, 5D, 4S, KC, then take all four away.
For example, if the four latest cards are 6C, 5D, 4S, KC, then take the 5D and 4S away.
Make sure your program introduces itself appropriately, describes the game briefly, pauses at appropriate times to let the user see what's going on, announces the removals (with reasons), and announces the result (win/loss) at the end.
Make good use of List methods.