Question: Java oriented program: I need a code that uses an array of references. This code will be designed to play a simplified version of the
Java oriented program:
I need a code that uses an array of references. This code will be designed to play a simplified version of the card game "WAR". However, for this code, there will be simplified rules of the game. Assume there exist two players for this simulation. (There is no human interaction with this code). Create a deck of cards. Shuffle the deck. Deal the deck into two face-down piles of 26 cards each. Turn over the top card for each player's pile and display the card using the toString() method. Whoever has the highest card out of the two cards wins the possession of both cards and places them in their "win" pile. If two cards turn up with the same value (use the getValue() method, each player then puts down an additional card into the center pile and turns over a second card. The owner of the higher of this newly turned over card wins all of the cards at play (the two original cards and the four additional). If this results in another tie, the same procedure is followed. Once the two original piles are depleted, count the number of cards owned by each player. The player with the highest number of cards wins the game.
Steps:
Create a class called Card. The card has three fields; a value, a suit and a face. The card class has a constructor that takes three values for the three fields.
Write a three get methods() to return the values of each of the fields.
Write a toString() method.
Write a compareTo() method that uses the value of the card to determine the ordering. For values, a face of "two" has a value of 2, a face of "three has a value of 3... For this game, Jack, Queen, King are valued in ascending order 11,12,13. Ace has the highest value.
Write an equals() method that returns true if the argument Card has the same suit and the same face as the invoking Card.
Create a class called Deck:
A deck has two fields- an array of Card references and an index to hold the subscript of the top card. The Deck class will only have one constructor which will create the array. The Deck class also has the getTopCard() method which returns a reference to the Card that is at the "top" of the array.
Also write a method shuffle which shuffles the array of cards. Generate random numbers and use these to exchange array elements. Exchange 100 times in this method.
Create the driver call ie Game:
This where the game logic will go. Create an instance of the deck class and call its shuffle () method. Deal the cards from the deck for each player.
Draw the cards, show the card and determine who wins the two cards or if a war is needed.
Once the game is won allow the user if he or she wants to play another game. Keep a running total of the number of games won by each of the two players. Human vs CPU.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
