Question: Complete the ConnectFour.java methods using the skeleton code provided. This class should compile with ConnectFourCLI.java and ConnectFourTester.java, which are contained in the same package. CONNECTFOUR.JAVA:
Complete the ConnectFour.java methods using the skeleton code provided. This class should compile with ConnectFourCLI.java and ConnectFourTester.java, which are contained in the same package.
CONNECTFOUR.JAVA:
package csgame;
import csgameutil.GamePhase;
import csgameutil.Token;
import csgameutil.TokenGrid;
@code ConnectFour represents a twoplayer connection game involving a twodimensional grid of
@linkplain csgameutil.Token tokens When a @code ConnectFour game object is
constructed, several instance variables representing the game's state are initialized and
subsequently accessible, either directly or indirectly, via "getter" methods. Over time, the
values assigned to these instance variables should change so that they always reflect the
latest information about the state of the game. Most of these changes are described in the
project's
functional requirements.
public class ConnectFour
INSTANCE VARIABLES: You should NOT modify the instance variable declarations below.
You should also NOT add any additional instance variables. Static variables should
also NOT be added.
private int rows; number of grid rows
private int cols; number of grid columns
private Token grid; D array of tokens in the grid
private Token player; D array of player tokens length
private int numDropped; number of tokens dropped so far
private int lastDropRow; row index of the most recent drop
private int lastDropCol; column index of the most recent drop
private GamePhase phase; current game phase
CONSTRUCTOR
Constructs a @link csgame.ConnectFour game with a grid that has @code rowsmany
rows and @code colsmany columns. All of the game's instance variables are expected to
be initialized by this constructor as described in the project's
functional
requirements.
@param rows the number of grid rows
@param cols the number of grid columns
@throws IllegalArgumentException if the value supplied for @code rows or @code cols is
not supported. The following values are supported: @code rows and
@code cols
public ConnectFourint rows, int cols
if rows rows cols cols
throw new IllegalArgumentExceptionUnsupported grid size.";
this.rows rows;
this.cols cols;
this.grid new Tokenrowscols;
this.player new TokenTokenPLAYERONE, Token PLAYERTWO;
this.numDropped ;
this.lastDropRow ;
this.lastDropCol ;
this.phase GamePhase.INPROGRESS;
ConnectFour
INSTANCE METHODS
Return the number of rows in the game's grid.
@return the number of rows
public int getRows
return rows;
getRows
Return the number of columns in the game's grid.
@return the number of columns
public int getCols
return cols;
getCols
Return whether @code row and @code col specify a location inside this game's grid.
@param row the position's row index
@param col the positions's column index
@return @code true if @code row and @code col specify a location inside this game's
grid and @code false otherwise
public boolean isInBoundsint row, int col
return row && row rows && col && col cols;
isInBounds
Return the grid @linkplain csgameutil.Token token located at the specified position
or @code null if no token has been dropped into that position.
@param row the token's row index
@param col the token's column index
@return the grid token located in row @code row and column @code col if it exists;
otherwise, the value @code null
@throws IndexOutOfBoundsExcepti
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
