Мне нужны мнения о том, как я могу завершить этот код для моей части модели моей игры в крестики-нолики. Я уже написал некоторый код, но у меня проблемы с закомментированными частями. У меня также есть большая часть представления и контроллера написано. Пока мой парень работает, но я не могу отобразить x и o, нажимая на них!
Снимок экрана
public class TicTacToeModel {
private Mark[][] board; /* Game board */
private boolean xTurn; /* True if X is current player */
private int size; /* Size of game board */
/* ENUM TYPE DEFINITIONS */
/* Mark (represents X, O, or an empty square */
public enum Mark {
X("X"),
O("O"),
EMPTY(" ");
private String symbol;
private Mark(String s) { symbol = s; }
@Override
public String toString() { return symbol; }
};
/* Result (represents the final state of the game: X wins, O wins, a TIE,
or NONE if the game is not yet over) */
public enum Result {
X("X"),
O("O"),
TIE("TIE"),
NONE("NONE");
private String symbol;
private Result(String s) { symbol = s; }
@Override
public String toString() { return symbol; }
};
/* CONSTRUCTOR */
public TicTacToeModel() {
this(TicTacToe.DEFAULT_SIZE);
}
/* CONSTRUCTOR */
public TicTacToeModel(int size) {
// SUPPLY YOUR CODE FOR THE EMPTY SECTIONS AS COMMENTED BELOW
/* Initialize size; set X to go first */
// SUPPLY YOUR CODE HERE
/* Create board (size x size) as a 2D array of Mark objects */
board = new Mark[size][size];
/* Initialize board by filling every square with empty marks */
// SUPPLY YOUR CODE HERE
}
public boolean makeMark(int row, int col) {
/* Use "isValidSquare()" to check if the specified location is in range,
and use "isSquareMarked()" to see if the square is empty! If the
specified location is valid, make a mark for the current player, then
toggle "xTurn" from true to false (or vice-versa) to switch to the
other player before returning TRUE. Otherwise, return FALSE. */
// SUPPLY YOUR CODE HERE
return false; // remove this later!
}
private boolean isValidSquare(int row, int col) {
/* Return TRUE if the specified row and col are within bounds */
// SUPPLY YOUR CODE HERE
return false; // remove this later!
}
private boolean isSquareMarked(int row, int col) {
/* Return TRUE if the square at specified location is marked */
// SUPPLY YOUR CODE HERE
return false; // remove this later!
}
public Mark getMark(int row, int col) {
/* Return the mark from the square at the specified location */
// SUPPLY YOUR CODE HERE
return null; // remove this later!
}
public Result getResult() {
/* Call "isMarkWin()" to see if X or O is the winner, if the game is a
TIE, or if the game is not over. Return the corresponding Result
value */
// SUPPLY YOUR CODE HERE
return null; // remove this later!
}
private boolean isMarkWin(Mark mark) {
/* Check the squares of the board to see if the mark specified in the
argument is the winner */
// SUPPLY YOUR CODE HERE
return false; // remove this later!
}
private boolean isTie() {
/* Check the squares of the board to see if the game is a tie */
// SUPPLY YOUR CODE HERE
return false; // remove this later!
}
public boolean isGameover() {
/* Return TRUE if the game is over */
// SUPPLY YOUR CODE HERE
boolean isGameover = true;
if(!isGameover)
{return true;}
else
return false; // remove this later!
}
public boolean isXTurn() {
/* Getter for xTurn */
return xTurn;
}
public int getSize() {
/* Getter for size */
return size;
}
}