Skip to content

Instantly share code, notes, and snippets.

@alexanderbazo
Last active October 25, 2016 11:15
Show Gist options
  • Save alexanderbazo/3e8b74267d8419794406 to your computer and use it in GitHub Desktop.
Save alexanderbazo/3e8b74267d8419794406 to your computer and use it in GitHub Desktop.
Compound board = new Compound()
private void initBoard(int fieldWidth, int fieldHeight) {
board = new Compound(0, 0);
for (int x = 0; x < ROWS; x++) {
for (int y = 0; y < COLUMNS; y++) {
Chessfield newField = getNewFieldForBoard(x, y, fieldWidth,fieldHeight);
board.add(newField);
}
}
}
private Chessfield getNewFieldForBoard(int xIndex, int yIndex,
int fieldWidth, int fieldHeight) {
Chessfield newField;
int xPos = xIndex * fieldWidth;
int yPos = yIndex * fieldHeight;
if ((xIndex + yIndex) % 2 == 0) {
newField = new Chessfield(xPos, yPos, fieldWidth, fieldHeight,Color.BLACK);
} else {
newField = new Chessfield(xPos, yPos, fieldWidth, fieldHeight,Color.WHITE);
}
return newField;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment