我正在尝试实现一种方法来替换2D数组中的元素之一
public class GameBoard {
public static final char EMPTY = '.';
public static final char PLAYER1 = 'X';
public static final char PLAYER2 = 'O';
public static final int ROWS = 6;
public static final int COLUMNS = 7;
private char[][] board;
public char[][] getBoard(){
return board;
}
public char[][] get_move( int move, char player) {
char[][] x = getBoard();
if (player == PLAYER1 || player == PLAYER2) {
for (int row = 0; row<ROWS; row++) {
if (x[row][move] == EMPTY) {
x[row][move] = player;
return x;
}
}
}
else {
return board;
}
return getBoard();
}
public static GameBoard setBoardForTest(int[] moves, GameBoard board){
char player = PLAYER1;
for(int move: moves){
board.getMove(move, player);
if(player == PLAYER1){
player = PLAYER2;
}
else{
player = PLAYER1;
}
}
return board;
}
但是,当我在setBoardForTest()方法中调用board.getMove(player,move)时却始终收到错误消息,即未为GameBoard类型定义getMove(int,char)方法
答案 0 :(得分:1)
您已定义方法get_move
,而不是getMove
。只需重命名它就可以了。