field.put 方法无法编译。我不断收到一个错误,指出电路板的类型需要是 char[][],但它已经是了。有人可以帮助我解决这个问题吗?
import java.util.HashMap;
public class Field {
private HashMap<String, char[][]> field;
public Field(Integer xAs, Integer yAs, char[][] board ,Integer difficulty){
for(int i = 0; i < board.length; i++){
char x = 'A';
char r = 1;
for(int j = 0; j < board[i].length; j++){
if(i == 0){
field.put(x + "" , board[i][j]);
}
if(j == board[i].length - 1){
field.add(r + "", board[i][j]);
}
else{
field.add(x + r, board[i][j]);
}
}
}
}
board[i][j]
是char
,而不是char[][]
,您需要将整个板添加到Map
或将声明更改为HashMap<String, Character>