我正在编写的 Battleship 程序中有三个类,一个驱动程序、一个域和一个助手类。我想使用 mutator 方法更改域类中 2D 字符数组中元素的值,但在尝试传递时不断收到“不兼容的类型:char 无法转换为 char[][]”错误帮助类中的数组到域类。我做错了什么或者有其他方法可以做到这一点。
public void hitOrMiss() {
char[][] tUGB = bShip.getUserGameboard();
char[][] tGB = bShip.getGameboard();
if (bShip.getGameboard()[bShip.getUserRow()][bShip.getUserCol()] == '0') {
System.out.println("You missed!");
tUGB[bShip.getUserRow()][bShip.getUserCol()] = 'O';
bShip.setUserGambeboard(tUGB[bShip.getUserRow()][bShip.getUserCol()]);
//this.userGameboard[userRow][userCol] = 'O';
this.misses++;
this.chances--;
} else {
System.out.println("You got a hit!");
this.hits++;
this.chances++;
this.userGameboard[userRow][userCol] = this.hit;
this.gameboard[userRow][userCol] = this.hit;
}
}
这是突变器类
public void setUserGambeboard(char[][] aUserGameboard){
this.userGameboard = aUserGameboard;