我需要关于如何为井字游戏的模型部分完成此代码的意见。 我已经写了一些代码,但是在注释掉的部分上遇到了麻烦。 我也写了大部分视图和控制器。到目前为止,我的男人正在工作,但单击它们时似乎无法使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"),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;
}
}