Question: Java Program Game Class: Update method playGame() to do the following Create a local variable of data type int called roll initialized to the value
Java Program
Game Class:
| Update method playGame() to do the following Create a local variable of data type int called roll initialized to the value of 0 In the for loop that loops through the players of the gamePrior to the call to player.rollDice(dice)instantiate an instance of class Roll that will store the selected dice of the player for each roll for the reference object described in the previous step, call method removeDice() passing as an argument the reference object to empty the ArrayList of class Die Add a while loop based on the condition that the selected dice ArrayList size is less than the maximum number of dice AND the player has not exceeded the maximum number of rolls Inside the while loop should be the followingThe call to player.rollDice(dice) Call to method selectDice() on class Player passing as argumentsThe original Roll object reference The Roll object for the dice to keep The int for the current roll number Increment the local variable roll of data type int After the while loop, call method selectCategory() in class Player passing as an argument the reference object of class Roll that represents the kept dice by the player |
Current Code in Game class:
package core;
import java.util.ArrayList; import java.util.Scanner;
public class Game { private int gameTurn; private ArrayList
public Game() { createPlayers(); displayPlayers(); playGame(); } private void createPlayers() { // instantiate the players ArrayList players = new ArrayList(); // get the human player name Scanner scan = new Scanner(System.in); System.out.println("Enter human player name"); String name = scan.next(); // instantiate the human player HumanPlayer hp = new HumanPlayer(); hp.setName(name); System.out.println(hp.getCount()); // instantiate the ai player AiPlayer ap = new AiPlayer(); ap.setName("AI Player"); System.out.println(ap.getCount()); // add players to array list players.add(hp); players.add(ap); } private void displayPlayers() { System.out.println("number of player " +Player.getCount()); System.out.println("***************************"); System.out.println("Players for this game are: "); System.out.println("***************************");
// loop through players and display information for(Player player : players) { System.out.println(player.getName()); } } private void playGame() { // instantiate the roll object to create the dice dice = new Roll(); // loop through each player and have them do one roll for(Player player : players) { // pass the roll object to the player System.out.println("**********************************"); System.out.println("Player " + player.getName() + " passed the dice"); System.out.println("Player " + player.getName() + " rolling the dice"); player.rollDice(dice); System.out.println("Displaying the dice values"); dice.displayDice(); System.out.println("**********************************"); } } public Roll getDice() { return dice; }
public void setDice(Roll dice) { this.dice = dice; } /** * @return the gameTurn */ public int getGameTurn() { return gameTurn; }
/** * @param gameTurn the gameTurn to set */ public void setGameTurn(int gameTurn) { this.gameTurn = gameTurn; }
/** * @return the players */ public ArrayList
/** * @param players the players to set */ public void setPlayers(ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
