-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathGame.java
More file actions
53 lines (42 loc) · 1.31 KB
/
Game.java
File metadata and controls
53 lines (42 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package domain;
import domain.board.Board;
import domain.piece.Piece;
import domain.player.Players;
import java.util.Map;
public class Game {
private Board board;
private final Players players;
public Game(Board board, Players players) {
this.board = board;
this.players = players;
}
public Side getCurrentSide() {
return players.getCurrentSide();
}
public Destinations selectSource(Position position) {
Piece piece = board.getPiece(position);
players.getCurrentPlayer().validateAlly(piece);
return findDestinations(position);
}
public void move(Position source, Position target) {
Destinations destinations = selectSource(source);
destinations.validateDestinations(target);
movePiece(source, target);
players.switchPlayer();
}
private Destinations findDestinations(Position position) {
return board.findDestinations(position);
}
private void movePiece(Position source, Position target) {
this.board = board.movePiece(source, target);
}
public Map<Position, Piece> getBoard() {
return board.getBoard();
}
public boolean isOver() {
return board.isGameOver();
}
public String getWinner() {
return players.getWaitingPlayerName();
}
}