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 cs1302.game;
import cs1302.gameutil.GamePhase;
import cs1302.gameutil.Token;
import cs1302.gameutil.TokenGrid;
/**
*{@code ConnectFour} represents a two-player connection game involving a two-dimensional grid of
*{@linkplain cs1302.gameutil.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; //2D array of tokens in the grid
private Token[] player; //1D array of player tokens (length 2)
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 cs1302.game.ConnectFour} game with a grid that has {@code rows}-many
* rows and {@code cols}-many 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 6<= rows <=9} and
*{@code 7<= cols <=9}.
*/
public ConnectFour(int rows, int cols){
if (rows <6|| rows >9|| cols <7|| cols >9){
throw new IllegalArgumentException("Unsupported grid size.");
}
this.rows = rows;
this.cols = cols;
this.grid = new Token[rows][cols];
this.player = new Token[]{Token.PLAYER_ONE, Token PLAYER_TWO};
this.numDropped =0;
this.lastDropRow =-1;
this.lastDropCol =-1;
this.phase = GamePhase.IN_PROGRESS;
}// 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!