-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathLadderController.java
82 lines (70 loc) · 2.97 KB
/
LadderController.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
package controller;
import domain.ladder.Ladder;
import domain.ladder.LadderLine;
import domain.results.Results;
import domain.users.User;
import domain.users.Users;
import service.ladder.LadderService;
import service.results.ResultsService;
import service.users.UserService;
import view.InputView;
import view.OutputView;
public class LadderController {
private final LadderService ladderService;
private final UserService userService;
private final ResultsService resultsService;
private final OutputView outputView;
private final InputView inputView;
public LadderController(final LadderService ladderService, final UserService userService, final ResultsService resultsService, final OutputView outputView, final InputView inputView) {
this.ladderService = ladderService;
this.userService = userService;
this.resultsService = resultsService;
this.outputView = outputView;
this.inputView = inputView;
}
public void start() {
userService.makeUsers(inputView.inputUserNames());
resultsService.makeResults(inputView.inputResults());
ladderService.makeLadder(userService.getUsers().users().size(), inputView.inputHeight());
userService.updatePosition(ladderService.getLadder(), userService.getUsers());
printLadder(userService.getUsers(), ladderService.getLadder(), resultsService.getResults());
printLadderResult(userService.getUsers(), resultsService.getResults());
}
private void printLadder(final Users users, final Ladder ladder, final Results results) {
for (User user : users.users()) {
outputView.printUser(user.getName());
}
outputView.printEmpty();
for (LadderLine ladderLine : ladder.ladderLines()) {
outputView.printLadderLine(ladderLine.line());
}
for (String result : results.results()) {
outputView.printResult(result);
}
outputView.printEmpty();
}
private void printLadderResult(final Users users, final Results results) {
while (true) {
final String wantedUserName = inputView.inputWantedUserName();
final boolean isAll = checkUserName(wantedUserName);
printResult(wantedUserName, users, results, isAll);
}
}
private boolean checkUserName(final String wantedUserName) {
return wantedUserName.equals("all");
}
private void printResult(final String wantedUserName, final Users users, final Results results, final boolean isAll) {
if (!isAll) {
outputView.printExecutionResult();
outputView.printUserResult(results.results()
.get(userService.findByName(wantedUserName).getPosition())
);
return;
}
outputView.printExecutionResult();
for (User user : users.users()) {
outputView.printAllUserResults(user.getName(), results.results()
.get(user.getPosition()));
}
}
}