Question: Using the constructor code and instance variables provided, complete these ConnectFour.java methods: getRows ( ) ; getCols ( ) ; isInBounds ( ) ; getTokenAt
Using the constructor code and instance variables provided, complete these ConnectFour.java methods:
getRows;
getCols;
isInBounds;
getTokenAt;
setPlayerTokens;
getPlayerToken;
getNumDropped;
getLastDropRow;
getLastDropCol;
getPhase;
dropToken;
isLastDropConnectFour;
CONNECTFOUR.JAVA BASE CODE:
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
The finished code should compile with ConnectFourTester.java and ConnectFourCLI.java, both of which are contained in the same package.
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
