mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
moved score out of game
This commit is contained in:
@@ -7,13 +7,12 @@ public abstract class Game {
|
|||||||
NORMAL,
|
NORMAL,
|
||||||
DRAW,
|
DRAW,
|
||||||
WIN,
|
WIN,
|
||||||
MOVE_SKIPPED,
|
|
||||||
|
TURN_SKIPPED,
|
||||||
}
|
}
|
||||||
|
|
||||||
public record Move(int position, char value) {}
|
public record Move(int position, char value) {}
|
||||||
|
|
||||||
public record Score(int player1Score, int player2Score) {}
|
|
||||||
|
|
||||||
public static final char EMPTY = (char)0;
|
public static final char EMPTY = (char)0;
|
||||||
|
|
||||||
public final int rowSize;
|
public final int rowSize;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.toop.game.reversi;
|
|||||||
|
|
||||||
import org.toop.game.Game;
|
import org.toop.game.Game;
|
||||||
import org.toop.game.TurnBasedGame;
|
import org.toop.game.TurnBasedGame;
|
||||||
import org.toop.game.tictactoe.TicTacToe;
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -17,6 +16,8 @@ public final class Reversi extends TurnBasedGame {
|
|||||||
private Set<Point> filledCells = new HashSet<>();
|
private Set<Point> filledCells = new HashSet<>();
|
||||||
private Move[] mostRecentlyFlippedPieces;
|
private Move[] mostRecentlyFlippedPieces;
|
||||||
|
|
||||||
|
public record Score(int player1Score, int player2Score) {}
|
||||||
|
|
||||||
public Reversi() {
|
public Reversi() {
|
||||||
super(8, 8, 2);
|
super(8, 8, 2);
|
||||||
addStartPieces();
|
addStartPieces();
|
||||||
@@ -150,7 +151,7 @@ public final class Reversi extends TurnBasedGame {
|
|||||||
if (getLegalMoves().length == 0) {
|
if (getLegalMoves().length == 0) {
|
||||||
skipMyTurn();
|
skipMyTurn();
|
||||||
if (getLegalMoves().length > 0) {
|
if (getLegalMoves().length > 0) {
|
||||||
return State.MOVE_SKIPPED;
|
return State.TURN_SKIPPED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Score score = getScore();
|
Score score = getScore();
|
||||||
@@ -191,7 +192,7 @@ public final class Reversi extends TurnBasedGame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Game.Score getScore(){
|
public Score getScore(){
|
||||||
int player1Score = 0, player2Score = 0;
|
int player1Score = 0, player2Score = 0;
|
||||||
for (int count = 0; count < rowSize * columnSize; count++) {
|
for (int count = 0; count < rowSize * columnSize; count++) {
|
||||||
if (board[count] == 'B') {
|
if (board[count] == 'B') {
|
||||||
@@ -201,7 +202,7 @@ public final class Reversi extends TurnBasedGame {
|
|||||||
player2Score += 1;
|
player2Score += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Game.Score(player1Score, player2Score);
|
return new Score(player1Score, player2Score);
|
||||||
}
|
}
|
||||||
public Move[] sortMovesFromCenter(Move[] moves, Move center) {
|
public Move[] sortMovesFromCenter(Move[] moves, Move center) {
|
||||||
int centerX = center.position()%columnSize;
|
int centerX = center.position()%columnSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user