Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

question part A part B 2. A multiplayer game called Token Pass has the following rules. Each player begins with a random number of tokens

question
image text in transcribed
image text in transcribed
part A
image text in transcribed
part B
image text in transcribed
2. A multiplayer game called Token Pass has the following rules. Each player begins with a random number of tokens (at least I, but no more than 10) that are placed on a linear game board. There is one position on the game board for each player. After the game board has been filled, a player is randomly chosen to begin the game. Each position on the board is numbered, starting with 0. The following rules apply for a player's turn. The tokens are collected and removed from the game board at that player's position. The collected tokens are distributed one at a time, to each player, beginning with the next player in order of increasing position. If there are still tokens to distribute after the player at the highest position gets a token, the next token will be distributed to the player at position 0. The distribution of tokens continues until there are no more tokens to distribute. The Token Pass game board is represented by an array of integers. The indexes of the array represent the player positions on the game board, and the corresponding values in the array represent the number of tokens that each player has. The following example illustrates one player's turn. Example The following represents a game with 4 players. The player at position 2 was chosen to go first. 1 Player 0 1 3 Tokens 3 2 6 10 The tokens at position 2 are collected and distributed as follows. Ist token - to position 3 (The highest position is reached, so the next token goes to position 0.) 2nd token - to position 0 3rd token - to position 1 4th token - to position 2 5th token - to position 3 (The highest position is reached, so the next token goes to position 0.) 6th token - to position 0 After player 2's turn, the values in the array will be as follows. 2 2 Player Tokens 0 5 1 3 3 12 The Token Pass game is represented by the Token Pass class. public class TokenPass { private int[] board; private int currentPlayer; * * /** Creates the board array to be of size playerCount and fills it with random integer values from 1 to 10, inclusive. Initializes currentPlayer to a random integer value in the range between 0 and playerCount-1, inclusive. @param playerCount the number of players public TokenPass(int playerCount) { /* to be implemented in part (a) */ } * * * * * /** Distributes the tokens from the current player's position one at a time to each player in the game. Distribution begins with the next position and continues until all the tokens have been distributed. If there are still tokens to distribute when the player at the highest position is reached the next token will be distributed to the player at position 0. Precondition: the current player has at least one token. Postcondition: the current player has not changed. public void distributeCurrentPlayerTokens() { /* to be implemented in part (b) */ } // There may be instance variables, constructors, and methods that are not shown. * * ) (a) Write the constructor for the Tokenpass class. The parameter playerCount represents the number of players in the game. The constructor should create the board array to contain playerCount elements and fill the array with random numbers between 1 and 10, inclusive. The constructor should also initialize the instance variable currentPlayer to a random number between 0 and playerCount-1, inclusive. Complete the Token Pass constructor below. /** Creates the board array to be of size playerCount and fills it with * random integer values from 1 to 10, inclusive. Initializes currentPlayer to a * random integer value in the range between 0 and playerCount-1, inclusive. @param playerCount the number of players public Token Pass(int playerCount) (b) Write the distributeCurrentPlayerTokens method. The tokens are collected and removed from the game board at the current player's position. These tokens are distributed, one at a time, to each player, beginning with the next higher position, until there are no more tokens to distribute. Class information repeated from the beginning of the question public class Token Pass private int board private int currentPlayer public Token Pass (int playerCount) public void distributeCurrentPlayerTokens() Complete method distributeCurrentPlayerTokens below. /** Distributes the tokens from the current player's position one at a time to each player in * the game. Distribution begins with the next position and continues until all the tokens have been distributed. If there are still tokens to distribute when the player at the highest position is reached the next token will be distributed to the player at position 0. Precondition: the current player has at least one token. Postcondition: the current player has not changed. public void distributeCurrentPlayer Tokens()

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_2

Step: 3

blur-text-image_3

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

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions