gpt4 book ai didi

java - 如何修复 'Method is undefined for type'错误

转载 作者:行者123 更新时间:2023-12-02 09:54:34 26 4
gpt4 key购买 nike

我正在尝试实现一种替换二维数组中的元素之一的方法

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) 时,我不断收到错误,该方法 getMove(int, char) 对于 GameBoard 类型未定义

最佳答案

您定义了方法get_move,而不是getMove。只需重命名它就可以了。

关于java - 如何修复 'Method is undefined for type'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56094039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com