Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java program you are to create a variation of the popular card game SOLITAIRE using stacks and queues. Here is a picture of the layout

Java program

you are to create a variation of the popular card game SOLITAIRE using stacks and queues. Here is a picture of the layout of the game. You can play the online version by clicking here. Game terms and design requirements are explained

  • Deck/Stock - A pile of cards, face down, which are left over after setting up the other layout areas. These are turned over one-at-a-time into the waste. For your program this pile of cards MUST be stored in a STACK.
  • Waste - The area where the cards from the deck/stock go when they are brought into play. Only cards from the stock can be played to the waste. Only the topmost card can be moved to either the foundation or to the tableau. For your program this pile of cards MUST be stored in a STACK.
  • Foundations - The aim of the games is to clear the tableau and move all the cards to the foundation. They are built up by suit from Ace(1) to King(13). Assume at the start of the game, the four ACEs are already placed on the foundation. For your program this pile of cards MUST be stored in four separate STACKs (one for each suit). Recommended you use an ARRAY of stacks for this.
  • Tableaus - This consists of a number of piles where cards can be moved from one tableau to another or from tableau to a foundation. For your program this pile of cards MUST be stored in 7 STACKs and 7 QUEUEs. Each tableau (ex. T4 see picture) has both a stack and a queue. The stack holds the cards that have been turned over while the queue holds the cards that have not yet turned. At the start of the game Tableau 0 (T0 see picture) starts with a queue containing 1 card, T1 has two cards, T2 has 3 cards and so on. The game begins by DEQUEUING one card from each of these queues and placing it into the stack of the tableau. Hence, the T0 queue begins the game with 0 cards, T1 queue has 1 card and so forth while each of the tableau stacks have the one card to start with (the topmost card you can see). Recommended you use an ARRAY of 7 queues and another ARRAY of 7 stacks for this.

Creating a shuffled deck of 52 cards Your deck of cards should be represented by a number (1-13) followed by the first letter of the suit. Example: 1H, 5S, 12C, 13D would mean ace of hearts(1H), 5 of spades(5S), queen of clubs(12C), and king of diamonds(13D). The deck also needs to be shuffled.

To get you started I have provided sample code you can begin with that generates 52 cards into a shuffled ArrayList (click here).

You MUST put the elements of this ArrayList into your deck stack yourself. Stacks and Queues You may use Java's ArrayDeque class and Java's Stack class or you may use your own StackBox / QueueBox code or any combination of these four BUT your solution must use stacks and queues as described above. *** Assume for all stacks you can only move and see (peek) the top card of any stack. Sample Program Download my program (executable only), unzip, and run runme.bat (click here). Replicate my program's look and behavior. Do not try to "decompile" this program. There are safeguards in place and detection of cheating will result in disciplinary action. Simple Game Rules

  • You can only move the top card of any stack.
  • To move a card to the foundation, the foundation must have the previous card already there. Example, you can't move 12D if 11D is not already in the foundation.
  • To move a card onto a tableau, the card must be one less than the card currently showing on the target tableau AND the suit color must be opposite color than the card showing. Example, moving 7H on a tableau currently showing a 8S is allowed but you can't move 7H to a 8D (suit colors are both red). You can also move any card to the tableau if the tableau is empty (no cards in its stack or queue left).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel 2024 In 7 Days

Authors: Alan Dinkins

1st Edition

B0CJ3X98XK, 979-8861224000

More Books

Students also viewed these Databases questions

Question

Discuss one of the four main economic questions.

Answered: 1 week ago

Question

Understanding Group Leadership Culture and Group Leadership

Answered: 1 week ago