Question
This assignment is about the three cushion game and it is implemented in Java. Method Summary All MethodsInstance MethodsConcrete Methods Modifier and Type Method Description
This assignment is about the three cushion game and it is implemented in Java.
Method Summary All MethodsInstance MethodsConcrete Methods
Modifier and Type Method Description void cueBallImpactCushion() Indicates the given ball has impacted the given cushion.
void cueBallStrike(BallType ball) Indicates the player's cue ball has struck the given ball.
void cueStickStrike(BallType ball) Indicates the cue stick has struck the given ball.
void endShot() Indicates that all balls have stopped motion.
void foul() A foul immediately ends the player's inning, even if the current shot has not yet ended.
BallType getCueBall() Gets the cue ball of the current player.
int getInning() Gets the inning number.
PlayerPosition getInningPlayer() Gets the current player.
int getPlayerAScore() Gets the number of points scored by Player A.
int getPlayerBScore() Gets the number of points scored by Player B.
boolean isBankShot() Returns true if and only if the most recently completed shot was a bank shot.
boolean isBreakShot() Returns true if and only if this is the break shot (i.e., the first shot of the game).
boolean isGameOver() Returns true if the game is over (i.e., one of the players has reached the designated number of points to win).
boolean isInningStarted() Returns true if the shooting player has taken their first shot of the inning.
boolean isShotStarted() Returns true if a shot has been taken (see cueStickStrike()), but not ended (see endShot()).
void lagWinnerChooses(boolean selfBreak, BallType cueBall) Sets whether the player that won the lag chooses to break (take first shot), or chooses the other player to break.
java.lang.String toString() Returns a one-line string representation of the current game state. Methods inherited from class java.lang.Object equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Constructor Details ThreeCushion public ThreeCushion(PlayerPosition lagWinner, int pointsToWin) Creates a new game of three-cushion billiards with a given lag winner and the predetermined number of points required to win the game. The inning count starts at 1. Parameters: lagWinner - either player A or B pointsToWin - the number of points a player needs to reach for the game to end Method Details
lagWinnerChooses public void lagWinnerChooses(boolean selfBreak, BallType cueBall) Sets whether the player that won the lag chooses to break (take first shot), or chooses the other player to break. If this method is called more than once it should have no effect. In other words, the lag winner can only choose these options once and may not change their mind afterwards. Parameters: selfBreak - if true the lag winner chooses to take the break shot cueBall - the lag winners chosen cue ball (either WHITE or YELLOW)
cueStickStrike public void cueStickStrike(BallType ball) Indicates the cue stick has struck the given ball. If a shot has not already begun, indicates the start of a new shot. If this method is called while a shot is still in progress (i.e., endShot() has not been called for the previous shot), the player has committed a foul (see the method foul()). Also, if the player strikes anything other than their own cue ball, they committed a foul. Calling this method signifies both the start of a shot and the start of an inning, assuming a shot or inning has not already begun, respectively.
Even if a foul has been committed, calling this method is considered the start of a shot. That includes even the case when the player strikes a ball other than their own cue ball. It is expected that the endShot() method will be called in any case to indicate the end of the shot.
No play can begin until the lag player has chosen who will break (see lagWinnderChooses). If this method is called before the break is chosen, it should do nothing.
If this method is called after the game has ended, it should do nothing.
cueBallStrike public void cueBallStrike(BallType ball) Indicates the player's cue ball has struck the given ball. A ball strike cannot happen before a stick strike. If this method is called before the start of a shot (i.e., cueStickStrike() is called), it should do nothing.
If this method is called after the game has ended, it should do nothing.
cueBallImpactCushion public void cueBallImpactCushion() Indicates the given ball has impacted the given cushion. A cushion impact cannot happen before a stick strike. If this method is called before the start of a shot (i.e., cueStickStrike() is called), it should do nothing.
If this method is called after the game has ended, it should do nothing.
endShot public void endShot() Indicates that all balls have stopped motion. If the shot was valid and no foul was committed, the player scores 1 point. The shot cannot end before it has started with a call to cueStickStrike. If this method is called before cueStickStrike, it should be ignored.
A shot cannot end before the start of a shot. If this method is called before the start of a shot (i.e., cueStickStrike() is called), it should do nothing.
If this method is called after the game has ended, it should do nothing.
foul public void foul() A foul immediately ends the player's inning, even if the current shot has not yet ended. When a foul is called, the player does not score a point for the shot. A foul may also be called before the inning has started. In that case the player whose turn it was to shot has their inning forfeited and the inning count is increased by one.
No foul can be called until the lag player has chosen who will break (see lagWinnerChooses()). If this method is called before the break is chosen, it should do nothing.
If this method is called after the game has ended, it should do nothing.
getPlayerAScore public int getPlayerAScore() Gets the number of points scored by Player A. Returns: the number of points getPlayerBScore public int getPlayerBScore() Gets the number of points scored by Player B. Returns: the number of points
getInning public int getInning() Gets the inning number. The inning count starts at 1. Returns: the inning number
getCueBall public BallType getCueBall() Gets the cue ball of the current player. If this method is called in between innings, the cue ball should be the for the player of the upcoming inning. If this method is called before the lag winner has chosen a cue ball, the cue ball is undefined (this method may return anything). Returns: the player's cue ball
getInningPlayer public PlayerPosition getInningPlayer() Gets the current player. If this method is called in between innings, the current player is the player of the upcoming inning. If this method is called before the lag winner has chosen to break, the current player is undefined (this method may return anything). Returns: the current player
isBreakShot public boolean isBreakShot() Returns true if and only if this is the break shot (i.e., the first shot of the game). Returns: true if this is the break shot, false otherwise
isBankShot public boolean isBankShot() Returns true if and only if the most recently completed shot was a bank shot. A bank shot is when the cue ball impacts the cushions at least 3 times and then strikes both object balls. Returns: true if shot was a bank shot, false otherwise
isShotStarted public boolean isShotStarted() Returns true if a shot has been taken (see cueStickStrike()), but not ended (see endShot()). Returns: true if the shot has been started, false otherwise
isInningStarted public boolean isInningStarted() Returns true if the shooting player has taken their first shot of the inning. The inning starts at the beginning of the shot (i.e., the shot may not have ended yet). Returns: true if the inning has started, false otherwise
isGameOver public boolean isGameOver() Returns true if the game is over (i.e., one of the players has reached the designated number of points to win). Returns: true if the game is over, false otherwise
toString public java.lang.String toString() Returns a one-line string representation of the current game state. The format is: Player A*: X Player B: Y, Inning: Z
The asterisks next to the player's name indicates which player is at the table this inning. The number after the player's name is their score. Z is the inning number. Other messages will appear at the end of the string.
Overrides: toString in class java.lang.Object Returns: one-line string representation of the game state
Step 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