Refactored Game to follow encapsulation principle

This commit is contained in:
2025-10-29 17:28:43 +01:00
parent 50713c5021
commit 5da0a02cc8
7 changed files with 152 additions and 139 deletions

View File

@@ -254,10 +254,10 @@ public class Connect4Game {
private void updateCanvas() {
canvas.clearAll();
for (int i = 0; i < game.board.length; i++) {
if (game.board[i] == 'X') {
for (int i = 0; i < game.getBoard().length; i++) {
if (game.getBoard()[i] == 'X') {
canvas.drawDot(Color.RED, i);
} else if (game.board[i] == 'O') {
} else if (game.getBoard()[i] == 'O') {
canvas.drawDot(Color.BLUE, i);
}
}

View File

@@ -258,10 +258,10 @@ public final class ReversiGame {
// Todo: this is very inefficient. still very fast but if the grid is bigger it might cause issues. improve.
canvas.clearAll();
for (int i = 0; i < game.board.length; i++) {
if (game.board[i] == 'B') {
for (int i = 0; i < game.getBoard().length; i++) {
if (game.getBoard()[i] == 'B') {
canvas.drawDot(Color.BLACK, i);
} else if (game.board[i] == 'W') {
} else if (game.getBoard()[i] == 'W') {
canvas.drawDot(Color.WHITE, i);
}
}
@@ -321,7 +321,7 @@ public final class ReversiGame {
Move[] moves = null;
if (isLegalMove) {
moves = game.getFlipsForPotentialMove(
new Point(cellEntered%game.columnSize,cellEntered/game.rowSize),
new Point(cellEntered%game.getColumnSize(),cellEntered/game.getRowSize()),
game.makeBoardAGrid(),
game.getCurrentPlayer());
}