-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathLadderController.java
More file actions
61 lines (45 loc) · 2.12 KB
/
LadderController.java
File metadata and controls
61 lines (45 loc) · 2.12 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
package nextstep.ladder.controller;
import engine.LinesCreator;
import factory.LinesFactory;
import nextstep.ladder.domain.LadderExecutor;
import nextstep.ladder.domain.ExecuteResult;
import nextstep.ladder.domain.LadderResult;
import nextstep.ladder.domain.MachingResult;
import nextstep.ladder.domain.Participants;
import nextstep.ladder.strategy.LadderLineStrategy;
import nextstep.ladder.view.InputView;
import nextstep.ladder.view.OutputView;
public class LadderController {
private final InputView inputView;
private final OutputView outputView;
public LadderController(InputView inputView, OutputView outputView) {
this.inputView = inputView;
this.outputView = outputView;
}
public void startLadder() {
String names = inputView.inputName();
int maxLadder = inputView.inputMaxLadder();
String executeResultStr = inputView.inputExecuteResult();
Participants participants = new Participants(names);
ExecuteResult executeResult = new ExecuteResult(participants.size(), executeResultStr);
LinesCreator linesCreator = LinesFactory.createNextStepLines(participants.size(), maxLadder, new LadderLineStrategy());
LadderExecutor ladderExecutor = new LadderExecutor(linesCreator, participants);
MachingResult machingResult = ladderExecutor.play();
LadderResult ladderResult = machingResult.map(participants, executeResult);
outputView.outputParticipants(participants);
outputView.outputResult(executeResult, linesCreator, ladderResult);
inputOutputFindResult(ladderResult);
outputView.outputParticipantAllResult(ladderResult);
}
private void inputOutputFindResult(LadderResult ladderResult) {
String participant = inputOutputResult(ladderResult);
if (!"all".equals(participant)) {
inputOutputResult(ladderResult);
}
}
private String inputOutputResult(LadderResult ladderResult) {
String participant = inputView.inputParticipantResult();
outputView.outputParticipantResult(ladderResult.getReward(participant));
return participant;
}
}