enter image description here / **检查每个单元格的边框是否与
*其邻居。例如,如果一个牢房没有东墙,
*那么它在东面的邻居应该没有 west 墙。
*
*具体来说:对于网格中的每个单元格以及每个方向,
*如果以下情况,该单元可能在该方向上有墙
*墙在网格的边缘,并且必须有墙
*如果它的邻居在那个方向
*在那个方向上有一个对应的墙。
*
* @return网格中的单元格是否具有有效的边框值。
* /
public boolean bordersAreValid(){
布尔结果= true;
for(int j = 0; j if (i==0 && !this.cells[j][i].hasWest()) {
result = false;
}
if (j== this.cells.length -1 && this.cells[j][i].hasSouth()) {
result = false;
}
if (i== this.cells.length -1 && this.cells[j][i].hasEast()) {
result = false;
}
} else {
Cell northneighbour; Cell southneighbour; Cell eastNeighbour; Cell westNeighbour;
northneighbour = this.cells[j-1][i];
southneighbour = this.cells[j+1][i];
eastNeighbour = this.cells[j][i+1];
westNeighbour = this.cells[j][i-1];
if (this.cells[j][i].hasNorth() && !northneighbour.hasSouth() ){
result = false;
}
if (this.cells[j][i].hasEast() && !northneighbour.hasWest() ){
result = false;
}
if (this.cells[j][i].hasWest() && !northneighbour.hasEast() ){
result = false;
}
if (this.cells[j][i].hasSouth() && !northneighbour.hasNorth() ){
result = false;
}
}
}
}
return result;
}