Question: Note: Although Tic - Tac - Toe and Mastermind allow only two players, Connect Four can be played with up to four players. For simplicity,
Note: Although TicTacToe and Mastermind allow only two players, Connect Four can be
played with up to four players. For simplicity, your code will handle only two players.
Select File New Enum to create an enumeration named Outcome in the
games.boards package defined as follows:
public enum Outcome PLAYERWIN, PLAYERWIN, CONTINUE, TIE
This enumeration represents the result when the turn is completed.
Select File New Enum to create an enumeration named Mark in the games.boards
package defined as follows:
public enum Mark EMPTY NOUGHT, CROSS, YELLOW, RED,
BLUE, GREEN, MAGENTA, ORANGE
This enumeration represents the result when the game is completed.
Note: Only yellow and red are used in Connect Four, while Mastermind uses all six colors.
Add the Cell class to the games.boards package. It should have the private variables
content, row, and column, and the public methods getContent, setContent, getRow, and
getColumn. Use the following code as a guide:
public class Cell
private Mark content;
private int row, column;
public Cellint row, int column
this.row row;
this.column column;
content Mark.EMPTY;
public Mark getContent return content;
public void setContentMark content
this.content content;
public int getRow return row;
public int getColumn return column;
Take note that all classes that support direct instantiation should have a constructor. In this
case, the constructor will be used by the Board class to create each of its cells.
Add the Board class to the games.boards package. It should have a twodimensional array
of Cell objects. The Board class should initialize a board with a specified number of columns
and rows, provide access to Cell objects, and display all of its cells correctly. Use the
following code as a guide:
public class Board
private Cell cells;
public Boardint rows, int columns
cells new Cellrowscolumns;
for int r ; r cells.length; r
for int c ; c cellsrlength; c
cellsrc new Cellrc;
public void setCellMark mark, int row, int column
throws IllegalArgumentException
if cellsrowcolumngetContent Mark.EMPTY
cellsrowcolumnsetContentmark;
else throw new IllegalArgumentException
Player already there!" ;
public Cell getCellint row, int column
return cellsrowcolumn;
public String toString
StringBuilder str new StringBuilder;
for int r ; r cells.length; r
strappend;
for int c ; c cellsrlength; c
switchcellsrcgetContent
case NOUGHT:
strappendO;
break;
case CROSS:
strappendX;
break;
case YELLOW:
strappendY;
break;
case RED:
strappendR;
break;
case BLUE:
strappendB;
break;
case GREEN:
strappendG;
break;
case MAGENTA:
strappendM;
break;
case ORANGE:
strappendM;
break;
default: Empty
strappend;
strappend;
strappend
;
return strtoString;
This code should seem familiar to you. The methods in theTicTacToeGame class are similar
to those in the Board class. The StringBuilder class was used instead of theString class for
better performance.
Add the following import statement to theBoardGameTester class:
import games.boards.;
In the main method of BoardGameTester, perform the following actions:
a Create a times board for a TicTacToe game.
b Create a times board for a Connect Four game.
c Create a times board for a game of Mastermind.
d Set a cell to a nought or cross on the TicTacToe board.
e Set a cell to yellow or red on the Connect Four board.
f Set a cell to yellow, red, green, blue, magenta, or orange on the Mastermind board.
g Display the boards for TicTacToe, Connect Four, and Mastermind.
Run the project to ensure it works as you expect it to
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
