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