Question
Need help with a java game of card program. The code should be written within the code in the picture. Directions are in the comment
Need help with a java game of card program. The code should be written within the code in the picture. Directions are in the comment code. Thanks.
import java.util.ArrayList;
import java.util.Scanner;
public class GameOfWar {
/**
*
* War
*
* Objective: Play until one player runs out of cards.
* Compare card values. The bigger value wins both cards.
* When there is a tie in the card value, decide based on suit.
* Winning a tie hand results in gaining two more of the opponents cards.
*
* Tie Game:
* Use suit ranking
* Ascending alphabetical order: clubs (lowest), followed by diamonds, hearts, and spades (highest).
* FYI... This ranking is used in the game of bridge.
*/
public static void main(String[] args) {
// The main method structure is generally setup for you but
// is missing several lines. You must have the three ArrayLists
//
Scanner myScan = new Scanner(System.in);
ArrayList
ArrayList
ArrayList
int restart = 1;
System.out.println("Welcome to War!");
while(restart == 1)
{
restartGame(pile, player1, player2);
createPile(pile);
deal(pile, player1, player2);
shuffle(player1);
shuffle(player2);
while(player1.size() > 0 && player2.size() > 0)
{
int value1 = getCardValue(player1.get(0));
int value2 = getCardValue(player2.get(0));
System.out.println(player1.get(0) + " vs. " + player2.get(0));
if(value1 > value2)
{
System.out.println("Player 1 wins that hand");
}
else if(value1
{
System.out.println("Player 2 wins that hand");
}
else // tie
{
// Winning tie hand not only get the two cards played, but two ADDITIONAL cards (see example)
// NOTE: You can only give cards that a player has.
// Suit order from value to most value "Clubs" , "Diamonds" , "Hearts", "Spades"
int player1suit = getSuitValue(player1.get(0));
int player2suit = getSuitValue(player2.get(0));
if(player1suit > player2suit)
{
System.out.println("TIE except Player 1 wins that hand by suit order!");
}
else
{
System.out.println("TIE except Player 2 wins that hand by suit order!");
}
// Shuffle the cards for the players when there is a tie... it reduces the pattern for the same cards.
// Without occasional shuffling, I found myself in an infinite loop after a while. It seemed like the
// cards had ordered themselves into big/small/big/small by the way I was placing the cards at the end of the deck.
// NOTE: You can only shuffle decks that have cards in them.
shuffle(player1);
shuffle(player2);
}
}
if(player1.size() == 0)
{
System.out.println("Player 2 won!");
}
else
{
System.out.println("Player 1 won!");
}
System.out.print("Would you like to play again? Press 1 for yes, any other number to exit.");
restart = myScan.nextInt();
}
System.out.println("Thanks for playing war!");
please ask me if you need the code in text format. Heres the code for 3/4 of the program cant put more due to limit.
public static void createPile(ArrayListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started