Question: Hello again experts. Can someone please help me with a card game program called Spades. I will try to break it down as simple as

Hello again experts. Can someone please help me with a card game program called Spades. I will try to break it down as simple as possible so that you have ample time to work on it. The first part is the instructions on what needs to be in each Class and the second part is the code for the Class that I have written so far.

Thank you in advance!

So the class that I need help with is the HumanPlayerUi.java.

------------------- This is the first block of instructions that should go with the class HumanPlayerUi.java ----------------------------------------?

Hello again experts. Can someone please help me with a card game

---------------- Here is the HumanPlayerUi.java code that I have completed right now -------------------------------------------

package userinterface;

import core.HumanPlayer; import core.Player; import constants.Constants; import java.awt.Color; import java.awt.Dimension; import java.util.ArrayList; import java.util.logging.Logger; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JButton;

public class HumanPlayerUi extends JPanel{ private HumanPlayer human; private ArrayList cards; private CardUi cardUi; public HumanPlayerUi(Player player){ human = (HumanPlayer)player; initComponents(); } private void initComponents(){ this.setBorder(BorderFactory.createTitledBorder(human.getName())); this.setMinimumSize(new Dimension(200, 180)); this.setPreferredSize(new Dimension(200, 180)); this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); displayCards(); } private void displayCards(){ cards = new ArrayList(); for(int c = 0; c

-------------- This is the main Spades.java code just in case you need it --------------------------

package spades;

//Have to make to point to the JOptionPane libary import javax.swing.JOptionPane; import core.Game; import userinterface.GameUi;

public class Spades {

/** * @param args the command line arguments */ public static void main(String[] args) { //System.out.println("Welcome to Spades!"); JOptionPane.showMessageDialog(null, "Let's Play Spades!"); //Instantiate an instance of class Game calling the no-argument constructor Game game = new Game(); GameUi ui = new GameUi(game); } }

-------------- Here is the Player.java Class just in case you need it --------------------------

package core;

import java.util.ArrayList;

public abstract class Player implements IPlayer { //Declare member variables private String name; private int bid; private int score; private int tricks; private ArrayList hand; /** * @return the hand */ public ArrayList getHand() { return hand; }

/** * @param hand the hand to set */ public void setHand(ArrayList hand) { this.hand = hand; }

//Set getter/setter for each member variables /** * @param name the name to set */ public void setName(String name) { this.name = name; }

/** * @return the bid */ public int getBid() { return bid; }

/** * @param bid the bid to set */ public void setBid(int bid) { this.bid = bid; }

/** * @return the score */ public int getScore() { return score; }

/** * @param score the score to set */ public void setScore(int score) { this.score = score; }

/** * @return the tricks */ public int getTricks() { return tricks; }

/** * @param tricks the tricks to set */ public void setTricks(int tricks) { this.tricks = tricks; } public String getName(){ return name; } //abstract of the method from IPlayer public abstract Card playCard(); public abstract int placeBid(); public Player(){ hand = new ArrayList(); } //Method that allows player to display hand public void displayHand(){ for(Card card : hand){ //System.out.println(card.getFace() + " of " + card.getSuit()); } } //Method that allows player to sort by suit public void sortBySuit(){ ArrayList sortedHand = new ArrayList(); while(hand.size() > 0){ int position = 0; Card firstCard = hand.get(0); for (int i = 1; i

-------------- Here is the HumanPlayer.java Class --------------------------

package core;

import java.util.Scanner; public class HumanPlayer extends Player{ //Implementing methods from class player @Override public Card playCard(){ return null; } /** * * @return */ @Override public int placeBid(){ //System.out.println(super.getName() + " place your bid"); Scanner scanner = new Scanner(System.in); int bid = scanner.nextInt(); if(bid

-------------- Here is the CardUi.java Class --------------------------

package userinterface; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.ImageIcon; import core.Card;

public class CardUi { private Card card; private ImageIcon imageIcon; private JButton button; private JLabel label; private int position; //CardUi getter & setter /** * @return the button */ public JButton getButton() { return button; }

/** * @return the label */ public JLabel getLabel() { return label; } //CardUi Custom Constructor public CardUi(){ selectFrontImage(); selectVerticalBackImage(); selectHorizontalBackImage(); } private void selectFrontImage(){ } private void selectVerticalBackImage(){ } private void selectHorizontalBackImage(){ } }

-------------- Here is the Game.java Class --------------------------

package core;

import constants.Constants; import constants.Constants.Suit; import java.util.ArrayList; import java.util.Scanner; import java.util.Random; import java.util.Iterator; import javax.swing.JOptionPane;

public class Game { //Member Variable private Suit trump = Suit.SPADES; private Player lead; private Player dealer; private Player wonTrick; private int round; private ArrayList teams; private Deck deck; private Scanner scan; private ArrayList table; private int dealerIdx; private Player leadPlayer; //This is the custom constructor public Game(){ createTeams(); //outputTeams(); generateDeck(); setTable(); dealHand(); //displayHand(); //play(); //playHand(); } //Set getter/setter for each member variables /** * @return the trump */ public Suit getTrump() { return trump; }

/** * @param trump the trump to set */ public void setTrump(Suit trump) { this.trump = trump; }

/** * @return the lead */ public Player getLead() { return lead; }

/** * @param lead the lead to set */ public void setLead(Player lead) { this.lead = lead; }

/** * @return the dealer */ public Player getDealer() { return dealer; }

/** * @param dealer the dealer to set */ public void setDealer(Player dealer) { this.dealer = dealer; }

/** * @return the wonTrick */ public Player getWonTrick() { return wonTrick; }

/** * @param wonTrick the wonTrick to set */ public void setWonTrick(Player wonTrick) { this.wonTrick = wonTrick; }

/** * @return the round */ public int getRound() { return round; }

/** * @param round the round to set */ public void setRound(int round) { this.round = round; }

/** * @return the teams */ public ArrayList getTeams() { return teams; }

/** * @param teams the teams to set */ public void setTeams(ArrayList teams) { this.teams = teams; }

/** * @return the deck */ public Deck getDeck() { return deck; }

/** * @param deck the deck to set */ public void setDeck(Deck deck) { this.deck = deck; }

/** * @return the scan */ public Scanner getScan() { return scan; }

/** * @param scan the scan to set */ public void setScan(Scanner scan) { this.scan = scan; } /** * @return the table */ public ArrayList getTable() { return table; }

/** * @param table the table to set */ public void setTable(ArrayList table) { this.table = table; } //Method for createTeam private void createTeams(){ String name; //Teams ArrayList instantiated setTeams((ArrayList) new ArrayList()); //TeamOne instantiated and add to ArrayList Team teamOne = new Team(); teamOne.setTeamName("Team One"); getTeams().add(teamOne); //TeamTwo instantiated and add to ArrayList Team teamTwo = new Team(); teamTwo.setTeamName("Team Two"); getTeams().add(teamTwo); //Add Human Player to Team One setScan(new Scanner(System.in)); //System.out.println("Enter human player name"); name = JOptionPane.showInputDialog(null,"Enter human player name"); /ame = getScan().next(); //Human Player get added to Team one HumanPlayer hp = new HumanPlayer(); hp.setName(name); //System.out.println("Human Player added to Team One"); teamOne.getTeam().add(hp); //Create and add AI Players to team for (int p = 1; p ) new ArrayList()); //Get teams in the game Team teamOne = teams.get(Constants.ONE); Team teamTwo = teams.get(Constants.TWO); //Get players for each team Player teamOnePlayerOne = teamOne.getTeam().get(Constants.ONE); Player teamOnePlayerTwo = teamOne.getTeam().get(Constants.TWO); Player teamTwoPlayerOne = teamTwo.getTeam().get(Constants.ONE); Player teamTwoPlayerTwo = teamTwo.getTeam().get(Constants.TWO); /*Explicitly add each player to the member variable that represent the game table, and alternating pattern so that a players can be added. */ getTable().add(0, teamOnePlayerOne); getTable().add(1, teamTwoPlayerOne); getTable().add(2, teamOnePlayerTwo); getTable().add(3, teamTwoPlayerTwo); //Select first dealer Random random = new Random(); dealerIdx = random.nextInt(Constants.NUM_PLAYERS); dealer = getTable().get(dealerIdx); //System.out.println("Players at the table are"); for(Player player : getTable()){ //System.out.println(player.getName()); } } //Method for dealHand private void dealHand(){ //System.out.println("Player " + dealer.getName() + " will deal the hand"); //Index to keep track of player's card int playerIdx; if(dealerIdx currentCard = deck.getDeck().iterator(); currentCard.hasNext();){ Card card = currentCard.next(); //System.out.println("Dealing " + card.getFace() + " of " + card.getSuit()); //Add card to player's hand //System.out.println("Adding to player " + getTable().get(playerIdx).getName() + " hand "); getTable().get(playerIdx).getHand().add(card); //Increment the player index until value of 3, then rest to 0 if(playerIdx == 3) playerIdx = 0; else playerIdx++; //Remove the card from the deck after it had been dealt currentCard.remove(); } } //Method for displayHand private void displayHand(){ for(Team team : teams){ //System.out.println("*******************************"); //System.out.println(" " + team.getTeamName().toUpperCase()); //System.out.println("*******************************"); for(Player player : team.getTeam()){ //System.out.println("Sorting hand by suit and face"); player.sortBySuit(); if(player instanceof HumanPlayer){ player.displayHand(); } } } } //Method for Play private void play(){ //System.out.println("***************"); //System.out.println("Play the game"); //System.out.println("*************** "); //System.out.println("****************"); //System.out.println("Get player bids"); //System.out.println("****************"); getBids(); } //Method for getBids private void getBids(){ int bidsPlaced = 0; //counter for bids placed int leadIdx; //set the lead player if(dealerIdx Update the class to add the following member variables 1. CardUi cardUi; Update method displayCards() to do the following 1. 2. a. In the for loop i. Instantiate the instance of class CardUi passing as arguments I. The instance of class Card in the player's hand at the looping variable's index The instance of class JButton created inside the for loop 2. ii. Set local variable of class JButton representing the card equal to method call getButton0) on class CardUi iii. Comment out the call to method setText0 on the instance of class JButton Update the class to add the following member variables 1. CardUi cardUi; Update method displayCards() to do the following 1. 2. a. In the for loop i. Instantiate the instance of class CardUi passing as arguments I. The instance of class Card in the player's hand at the looping variable's index The instance of class JButton created inside the for loop 2. ii. Set local variable of class JButton representing the card equal to method call getButton0) on class CardUi iii. Comment out the call to method setText0 on the instance of class JButton

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!