Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a TicTacToe game in Java using these template codes (TicTacToeGame.java, TicTacToe.java, CellValue.java, GameState.java): Do not modify the code provided. TicTacToeGame.java /** * The class

Create a TicTacToe game in Java using these template codes (TicTacToeGame.java, TicTacToe.java, CellValue.java, GameState.java): Do not modify the code provided. TicTacToeGame.java

/**

* The class TicTacToeGame is the

* class that implements the Tic Tac Toe Game.

* It contains the grid and tracks its progress.

* It automatically maintain the current state of

* the game as players are making moves.

*/

public class TicTacToeGame {

// FINISH THE VARIABLE DECLARATION

/**

* The board of the game, stored as a one dimension array.

*/

static String[] board;

/**

* level records the number of rounds that have been

* played so far.

*/

int level;

/**

* gameState records the current state of the game.

*/

int gameState;

/**

* lines is the number of lines in the grid

*/

int lines;

/**

* columns is the number of columns in the grid

*/

int columns;

/**

* sizeWin is the number of cell of the same type

* that must be aligned to win the game

*/

int sizeWin;

/**

* default constructor, for a game of 3x3, which must

* align 3 cells

*/

public TicTacToeGame(){

// YOUR CODE HERE

}

/**

* constructor allowing to specify the number of lines

* and the number of columns for the game. 3 cells must

* be aligned.

* @param lines

* the number of lines in the game

* @param columns

* the number of columns in the game

*/

public TicTacToeGame(int lines, int columns){

// YOUR CODE HERE

}

/**

* constructor allowing to specify the number of lines

* and the number of columns for the game, as well as

* the number of cells that must be aligned to win.

* @param lines

* the number of lines in the game

* @param columns

* the number of columns in the game

* @param sizeWin

* the number of cells that must be aligned to win.

*/

public TicTacToeGame(int lines, int columns, int sizeWin){

// YOUR CODE HERE

}

/**

* getter for the variable lines

* @return

* the value of lines

*/

public int getLines(){

// YOUR CODE HERE

return;

}

/**

* getter for the variable columns

* @return

* the value of columns

*/

public int getColumns(){

// YOUR CODE HERE

return;

}

/**

* getter for the variable level

* @return

* the value of level

*/

public int getLevel(){

// YOUR CODE HERE

return;

}

/**

* getter for the variable sizeWin

* @return

* the value of sizeWin

*/

public int getSizeWin(){

// YOUR CODE HERE

return;

}

/**

* getter for the variable gameState

* @return

* the value of gameState

*/

public GameState getGameState(){

// YOUR CODE HERE

return;

}

/**

* returns the cellValue that is expected next,

* in other word, which played (X or O) should

* play next.

* This method does not modify the state of the

* game.

* @return

* the value of the enum CellValue corresponding

* to the next expected value.

*/

public CellValue nextCellValue(){

// YOUR CODE HERE

return;

}

/**

* returns the value of the cell at

* index i.

* If the index is invalid, an error message is

* printed out. The behaviour is then unspecified

* @param i

* the index of the cell in the array board

* @return

* the value at index i in the variable board.

*/

public CellValue valueAt(int i) {

// YOUR CODE HERE

return;

}

/**

* This method is called when the next move has been

* decided by the next player. It receives the index

* of the cell to play as parameter.

* If the index is invalid, an error message is

* printed out. The behaviour is then unspecified

* If the chosen cell is not empty, an error message is

* printed out. The behaviour is then unspecified

* If the move is valide, the board is updated, as well

* as the state of the game.

* To faciliate testing, is is acceptable to keep playing

* after a game is already won. If that is the case, the

* a message should be printed out and the move recorded.

* the winner of the game is the player who won first

* @param i

* the index of the cell in the array board that has been

* selected by the next player

*/

public void play(int i) {

// YOUR CODE HERE

}

/**

* A helper method which updates the gameState variable

* correctly after the cell at index i was just set in

* the method play(int i)

* The method assumes that prior to setting the cell

* at index i, the gameState variable was correctly set.

* it also assumes that it is only called if the game was

* not already finished when the cell at index i was played

* (i.e. the game was playing). Therefore, it only needs to

* check if playing at index i has concluded the game, and if

* set the oucome correctly

*

* @param i

* the index of the cell in the array board that has just

* been set

*/

private void setGameState(int i){

// YOUR CODE HERE

}

/**

* Returns a String representation of the game matching

* the example provided in the assignment's description

*

* @return

* String representation of the game

*/

public String toString(){

// YOUR CODE HERE

}

}

TicTacToe.java

image text in transcribed

CellValue.java

image text in transcribed

GameState.java

image text in transcribed

import java.io.Console; public class TicTacToe{ * main of the application. Creates the instance of TicTacToeGame * and starts the game. If two parameters lines and columns * are passed, they are used. If the paramters lines, columns * and win are passed, they are used. * Otherwise, a default value is used. Defaults values (3) are also * used if the paramters are too small (less than 2). * Here, we assume that the command lines arguments are indeed integers * @param args command lines parameters Run Debug public static void main(String[] args) { StudentInfo.display(); Console console = System.console(); TicTacToeGame game; int lines, columns, win; lines = 3; columns = 3; win = 3; if (args.length >= 2) { lines = Integer.parseInt(args[@]); if(lines= 3){ win = Integer.parseInt(args[2]); if(win 3){ System.out.println("Too many arguments. Only the first 3 are used."); game = new TicTacToeGame(lines, columns, win); // YOUR CODE HERE * An enum class that defines the * values EMPTY, x and O. enum CellValue { // YOUR CODE HERE 11 } /* * An enum class that defines the * values PLAYING, DRAW, * XWIN and OWIN WEBOVOU AWNE enum GameState // YOUR CODE HERE import java.io.Console; public class TicTacToe{ * main of the application. Creates the instance of TicTacToeGame * and starts the game. If two parameters lines and columns * are passed, they are used. If the paramters lines, columns * and win are passed, they are used. * Otherwise, a default value is used. Defaults values (3) are also * used if the paramters are too small (less than 2). * Here, we assume that the command lines arguments are indeed integers * @param args command lines parameters Run Debug public static void main(String[] args) { StudentInfo.display(); Console console = System.console(); TicTacToeGame game; int lines, columns, win; lines = 3; columns = 3; win = 3; if (args.length >= 2) { lines = Integer.parseInt(args[@]); if(lines= 3){ win = Integer.parseInt(args[2]); if(win 3){ System.out.println("Too many arguments. Only the first 3 are used."); game = new TicTacToeGame(lines, columns, win); // YOUR CODE HERE * An enum class that defines the * values EMPTY, x and O. enum CellValue { // YOUR CODE HERE 11 } /* * An enum class that defines the * values PLAYING, DRAW, * XWIN and OWIN WEBOVOU AWNE enum GameState // YOUR CODE HERE

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

Step: 3

blur-text-image

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions