class Board {
Direction[][] board;
Integer width;
Integer height;
Board(Integer width, Integer height) {
this.width = width;
this.height = height;
board = new Direction[width][height];
for (Integer y = 0; y < height; y++) {
for (Integer x = 0; x < width; x++) {
board[x][y] = Direction.Down;
}
}
}
Direction direction(Integer x, Integer y) {
return board[x][y];
}
void update(Integer x, Integer y) {
board[x][y].next();
}
}
在Direction
枚舉值是:Up
或Down
整個構建有相同的元素列表中的Java
首先,我要初始化我的板,使所有在板的每一個地方的初始值設置爲Down
。
其次,我想檢索在特定(X,Y)的值的所述板的
第三,我希望能夠在板的該特定元素來更新值的位置。 next()
函數旨在將值從Down
更改爲Up
,反之亦然。這是分開申報的。
我相信我在做代碼編譯時做錯了事,但是我的程序不能正常工作。
「但是我的程序不能正常工作,因爲它應該。」你能指定嗎? – toto2
你的「棋盤」沒有正確初始化? – Kal
@toto基本上,當我嘗試運行該程序時,我的空白屏幕上顯示的是相對背景色的「Down」。沒有其他發生。同樣,如果我將上面的'Direction.Up'設置爲其他顏色,但沒有任何反應。 – maclunian