-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathLadderController.java
More file actions
56 lines (46 loc) · 1.77 KB
/
Copy pathLadderController.java
File metadata and controls
56 lines (46 loc) · 1.77 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
package controller;
import domain.*;
import view.InputView;
import 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 run() {
Players players = inputView.readPlayers();
Rewards rewards = inputRewards(players);
LadderHeight height = new LadderHeight(inputView.readHeight());
Ladder ladder = Ladder.generate(new LadderWidth(players.size()), height, new RandomBooleanGenerator());
outputView.printLadderBoard(players, ladder, rewards);
GameResult gameResult = createGameResult(players, rewards, ladder);
printTargetResults(gameResult);
}
private Rewards inputRewards(Players players) {
Rewards rewards = inputView.readRewards();
players.validateMatch(rewards);
return rewards;
}
private GameResult createGameResult(Players players, Rewards rewards, Ladder ladder) {
LadderResult ladderResult = ladder.play(new LadderWidth(players.size()));
return GameResult.of(players, rewards, ladderResult);
}
private void printTargetResults(GameResult gameResult) {
while (true) {
String target = inputView.readTargetPerson();
if (processTarget(target, gameResult)) {
break;
}
}
}
private boolean processTarget(String target, GameResult gameResult) {
if ("all".equals(target)) {
outputView.printAllResults(gameResult);
return true;
}
outputView.printSingleResult(gameResult.findByName(target));
return false;
}
}