mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Applied encapsulation principle to TurnBasedBame.java
This commit is contained in:
@@ -109,7 +109,7 @@ public class Connect4 extends TurnBasedGame {
|
||||
}
|
||||
|
||||
private char getCurrentValue() {
|
||||
return currentTurn == 0 ? 'X' : 'O';
|
||||
return this.getCurrentTurn() == 0 ? 'X' : 'O';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package org.toop.game;
|
||||
|
||||
public abstract class TurnBasedGame extends Game {
|
||||
public final int turns;
|
||||
|
||||
protected int currentTurn;
|
||||
private final int turns;
|
||||
private int currentTurn;
|
||||
|
||||
protected TurnBasedGame(int rowSize, int columnSize, int turns) {
|
||||
super(rowSize, columnSize);
|
||||
|
||||
@@ -50,7 +50,7 @@ public final class Reversi extends TurnBasedGame {
|
||||
public Move[] getLegalMoves() {
|
||||
final ArrayList<Move> legalMoves = new ArrayList<>();
|
||||
char[][] boardGrid = makeBoardAGrid();
|
||||
char currentPlayer = (currentTurn==0) ? 'B' : 'W';
|
||||
char currentPlayer = (this.getCurrentTurn()==0) ? 'B' : 'W';
|
||||
Set<Point> adjCell = getAdjacentCells(boardGrid);
|
||||
for (Point point : adjCell){
|
||||
Move[] moves = getFlipsForPotentialMove(point,boardGrid,currentPlayer);
|
||||
@@ -176,7 +176,7 @@ public final class Reversi extends TurnBasedGame {
|
||||
}
|
||||
|
||||
public char getCurrentPlayer() {
|
||||
if (currentTurn == 0){
|
||||
if (this.getCurrentTurn() == 0){
|
||||
return 'B';
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -98,6 +98,6 @@ public final class TicTacToe extends TurnBasedGame {
|
||||
}
|
||||
|
||||
private char getCurrentValue() {
|
||||
return currentTurn == 0 ? 'X' : 'O';
|
||||
return this.getCurrentTurn() == 0 ? 'X' : 'O';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user