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();
}
}
The enumerated values in Direction
are: Up
or Down
Firstly, I want to initialise my board so that all the initial values at every place of the board are set to Down
.
Secondly, I want to retrieve the value at a particular (x,y) position of of the board
Thirdly, I want to be able to update the value at that particular element of the board. The next()
function is designed to change the value from Down
to Up
or vice versa. This is declared separately.
I believe I am doing something wrong as the code compiles, however my program doesn't work as it should.