我正在寫一個代碼,它將數組單元格的顏色更改爲黑色或白色,具體取決於原始顏色。如果電池是白色的,它會變成黑色,反之亦然。使用布爾數組創建類的新實例
public class Grid {
boolean[][] grid;
private int Height;
private int Width;
public White;
public Black;
public Grid(int height, int width) {
Height = height;
Width = width;
}
public int getHeight() {
return Height;
}
public int getWidth() {
return Width;
}
public boolean isWhite(int i, int j) {
boolean [][] Grid = new boolean [Height][Width];
for (i = 0; i<Height ; i++);{
for (j = 0; j<Width ; j++){
if (Grid[i][j] ?? //iswhite) {
??//setBlack
}
else (??)//setWhite
}
}
}}
protected void setWhite(int i, int j) {
??
}
protected void setBlack(int i, int j) {
??
}
}
我相信我應該網格[i] [j]取決於布爾值,但我不知道如何確實和「創建一個實例:我用下面的代碼工作公共布爾isWhite'到'setWhite'和'setBlack'。我應該怎麼做呢?
注:大多數網格/圖/等等。以[x] [y]方式設置。我注意到你先與y/height一起去了,所以我堅持這一點。 – Maple
我其實還有另一個班,應該照顧那個(我還沒有做,你很可能會在這裏找到我)。謝謝你的幫助 – Emfat