-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathBridgeGameController.java
More file actions
55 lines (46 loc) · 1.55 KB
/
BridgeGameController.java
File metadata and controls
55 lines (46 loc) · 1.55 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
54
55
package bridge;
import view.InputView;
import view.OutputView;
import java.util.*;
public class BridgeGameController {
private final BridgeGame bridgeGame;
private int tryCount = 0;
public BridgeGameController(List<String> bridge) {
this.bridgeGame = new BridgeGame(bridge);
}
public void run() {
while (true) {
BridgeGameResult bridgeGameResult = play();
tryCount++;
if (isGameEnd(bridgeGameResult)) {
OutputView.printGameResultMessage(bridgeGameResult, tryCount);
return;
}
bridgeGame.retry();
}
}
private BridgeGameResult play() {
boolean isSuccess = true;
for (int turn = 0; turn < bridgeGame.getSize() && isSuccess; turn++) {
String moving = InputView.readMoving();
System.out.println(moving);
isSuccess = bridgeGame.move(moving);
OutputView.printMap(bridgeGame.getBridgeBoard());
System.out.println();
}
BridgeGameResult bridgeGameResult = new BridgeGameResult(
bridgeGame.getBridgeBoard(),
isSuccess);
return bridgeGameResult;
}
boolean isGameEnd(BridgeGameResult bridgeGameResult) {
if (!bridgeGameResult.isSuccess) {
String gameCommand = InputView.readGameCommand(); // gameCommand 선언을 이동
System.out.println(gameCommand);
if (gameCommand.equals("R")) {
return false;
}
}
return true;
}
}