Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE JAVA PLEASE. You are to design a simple card game called War (see http://www.bicyclecards.com/how-to-play/war/ for a detailed description of the card game). In this

USE JAVA PLEASE.

You are to design a simple card game called War (see http://www.bicyclecards.com/how-to-play/war/ for a detailed description of the card game). In this game, there are two players who each get half the deck of cards (26 cards each). Players, at the same time, flip over the top card on their pile. The player who flips the higher value/rank card wins and gets both cards. The winning player adds both cards to their pile of cards. If both players flip over cards with the same value/rank, then a "War" starts. When "War" is declared both players put four cards into a separate pile and flip over the top card. The player who flips over the highest card wins the "War" pile. If the players both turn over the same card while at War, you play War again (etc.). The game then resumes as normal (one card at a time). The game ends when one player runs out of cards. The winner has all the cards. You can play an online version of the game here https://cardgames.io/war/.

You will have three Classes (Card, Deck and a Demo Class).

Card Class

You need to first create a Card Class. A Card object is made up of a suit (which are Hearts, Diamonds, Clubs, and Spades). Each suit has the same set of ranked cards: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace. And each card has a value (e.g., you could make Ace=14, King=13, Queen=12, Jack=11, then the numbered values e.g., "2" has a value of 2, "8" has a value of 8. The suit of the card doesn't matter in this game (that is only the rank and value of a card matter but you need to print out the suit in your output).

The order of best to worst cards: Ace, King, Queen, Jack, 10, 9, 8, 7, 6, 5, 4, 3, 2. Nothing beats an Ace and a 2 doesn't beat anything.

Deck Class

You will then create a Class called Deck. This class will store the Cards as an ArrayList (52 cards in total made up of 4 suites of cards) a "deck" of cards. You will also need to have methods related to a deck of cards a way to create and populate the ArrayList with all the different Cards, get and set methods, and in particular a shuffle method. The shuffle method will reorder the cards in the ArrayList into a random order. There are many ways that you can shuffle a deck of cards. You can search for an algorithm for shuffling (make sure you reference any source you sue) or you can use a simple approach of generating two random indices in the deck and swapping the cards several times (e.g., 52).

Demo Class (play the game)

In your Demo class, you will ask two players for their names, create a deck of cards and shuffle them. Then you will "deal" the cards into two hands (give each player their own pile of cards) so that each player has 26 cards (that is each player will have their own ArrayList with their pile of cards). Then play the game. This is an automated game, meaning once you start the game, the cards in each players hand (pile) will automatically keep flipping until a winner is found.

Note, your display must be like the above. You can use the printf function to help you format strings so that the columns line up. See this source to help you format your printf:

https://alvinalexander.com/programming/printf-format-cheat-sheet.

See the below sample output, for an example of how the game plays.image text in transcribed

Welcome to WAR! Let's Play!.v Enter the first player's name: BOB Enter the second player's name: SUE BOB 2 Clubs 9 Clubs King Spades 6 Spades #Cards 26 25 24 25 SUE Jack Hearts Ace Clubs Jack Spades 6 Diamonds #Cards 26 27 28 27 Winner SUE SUE BOB WAR 4 Spades 25 6 Hearts 27 SUE 9 Hearts 20 10 Diamonds 32 SUE ....... 5 Clubs Queen Spades 51 SUE SUE Wins! Congratulations Play again (y)? n- Welcome to WAR! Let's Play!.v Enter the first player's name: BOB Enter the second player's name: SUE BOB 2 Clubs 9 Clubs King Spades 6 Spades #Cards 26 25 24 25 SUE Jack Hearts Ace Clubs Jack Spades 6 Diamonds #Cards 26 27 28 27 Winner SUE SUE BOB WAR 4 Spades 25 6 Hearts 27 SUE 9 Hearts 20 10 Diamonds 32 SUE ....... 5 Clubs Queen Spades 51 SUE SUE Wins! Congratulations Play again (y)? n

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

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions