-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathLadderController.java
More file actions
75 lines (60 loc) · 2.22 KB
/
LadderController.java
File metadata and controls
75 lines (60 loc) · 2.22 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package controller;
import model.Ladder;
import model.LadderSize;
import model.Line;
import model.LadderFactory;
import model.LadderGame;
import model.BuildLine;
import view.InputView;
import view.OutputView;
import java.util.ArrayList;
import java.util.List;
public class LadderController {
private final LadderFactory factory = new LadderFactory();
private final OutputView outputView = new OutputView();
private final InputView inputView = new InputView();
public void run() {
List<String> participants = inputView.inputParticipants();
int width = participants.size();
List<String> results;
while (true) {
results = inputView.inputResults();
if (participants.size() == results.size()) {
break;
}
outputView.printError("참여자 수와 결과 수가 일치하지 않습니다.");
}
int height;
while (true) {
height = inputView.heightSize();
if (height >= 1) {
break;
}
outputView.printError("높이는 1이상이어야 합니다.");
}
LadderSize size = new LadderSize(width, height);
Ladder ladder = factory.create(size, width);
List<String> lines = new ArrayList<>();
for (Line line : ladder.lines()) {
lines.add(BuildLine.build(line));
}
outputView.printLadder(participants, lines, results);
LadderGame game = new LadderGame(ladder, participants.size());
playGame(game, participants, results);
}
private void playGame(LadderGame game, List<String> participants, List<String> results) {
while (true) {
String queryName = inputView.inputQueryName();
if ("all".equals(queryName)) {
outputView.printAllResults(game.playAll(participants, results));
break;
}
if (!participants.contains(queryName)) {
outputView.printError("존재하지 않는 이름입니다.");
continue;
}
String result = game.getResult(queryName, participants, results);
outputView.printSingleResult(queryName, result);
}
}
}