-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathJanggiController.java
More file actions
46 lines (40 loc) · 1.41 KB
/
JanggiController.java
File metadata and controls
46 lines (40 loc) · 1.41 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
package controller;
import domain.board.FormationType;
import domain.game.JanggiGame;
import domain.game.Team;
import domain.position.Position;
import java.util.List;
import view.InputView;
import view.OutputView;
public class JanggiController {
private final InputView inputView;
private final OutputView outputView;
public JanggiController(InputView inputView, OutputView outputView) {
this.inputView = inputView;
this.outputView = outputView;
}
public void run() {
JanggiGame game = createGame();
outputView.printBoard(game.getBoard());
while (game.isRunning()) {
playTurn(game);
}
}
private JanggiGame createGame() {
FormationType choFormation = FormationConverter.convert(inputView.initialFormation(Team.CHO));
FormationType hanFormation = FormationConverter.convert(inputView.initialFormation(Team.HAN));
return JanggiGame.of(choFormation, hanFormation);
}
private void playTurn(JanggiGame game) {
while (true) {
try {
List<Position> positions = inputView.askMovePiecePosition(game.currentTurn());
game.move(positions.get(0), positions.get(1));
outputView.printBoard(game.getBoard());
return;
} catch (IllegalArgumentException e) {
outputView.printError(e.getMessage());
}
}
}
}