-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathLadderGameController.java
91 lines (74 loc) · 2.84 KB
/
LadderGameController.java
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package controller;
import model.*;
import view.InputView;
import view.OutputView;
import java.util.InputMismatchException;
public class LadderGameController {
private LadderGame ladderGame;
private final LadderGenerator ladderGenerator = new LadderGenerator(new LadderConnectionGenerator());
public void inputGameInfos() {
PlayerNames playerNames = inputPlayerNames();
PrizeNames prizeNames = inputPrizeNames(playerNames.size());
int ladderHeight = inputLadderHeight();
ladderGame = new LadderGame(ladderGenerator, playerNames, prizeNames, ladderHeight);
}
public void showGameStatus() {
OutputView.printGameStatus(ladderGame.getGameStatus());
}
public void showGameResult() {
while (true) {
PlayerName playerNameForResult = InputView.inputPlayerNameForResult();
if (playerNameForResult.getName().equals("all")) {
OutputView.printAllPlayersResult(ladderGame.getAllPlayersResult());
continue;
}
if (playerNameForResult.getName().equals("exit")) {
OutputView.printExitMessage();
break;
}
OutputView.printPlayerResult(ladderGame.getPlayerPrize(playerNameForResult));
}
}
private PlayerNames inputPlayerNames() {
while (true) {
try {
return InputView.inputPlayerNames();
} catch (IllegalArgumentException e) {
OutputView.printErrorMessage(e.getMessage());
}
}
}
private PrizeNames inputPrizeNames(int prizeCount) {
while (true) {
try {
return InputView.inputPrizeNames();
} catch (IllegalArgumentException e) {
OutputView.printErrorMessage(e.getMessage());
}
}
}
private int inputLadderHeight() {
while (true) {
try {
int ladderHeight = InputView.inputLadderHeight();
if (ladderHeight <= 0) {
throw new IllegalArgumentException("사다리 높이를 양수로 입력해주세요.");
}
return ladderHeight;
} catch (NumberFormatException e) {
OutputView.printErrorMessage("사다리 높이를 정수로 입력해주세요!");
} catch (IllegalArgumentException e) {
OutputView.printErrorMessage(e.getMessage());
}
}
}
private PlayerName inputPlayerNameForResult() {
while (true) {
try {
return inputPlayerNameForResult();
} catch (IllegalArgumentException e) {
OutputView.printErrorMessage(e.getMessage());
}
}
}
}