-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathLadderGameController.java
94 lines (68 loc) · 2.83 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
92
93
94
import domain.*;
import view.InputView;
import view.OutputView;
import java.util.List;
public class LadderGameController {
private final InputView inputView;
private final OutputView outputView;
public LadderGameController(InputView inputView, OutputView outputView) {
this.inputView = inputView;
this.outputView = outputView;
}
public void ladderGame() {
List<Person> people = readParticipants();
List<Prize> prizes = readPrizes();
validateInputsCount(people.size(), prizes.size());
int height = readLadderHeight();
int width = people.size();
LadderFactory ladderGenerator = new RandomLadderFactory(height, width);
Ladder ladder = ladderGenerator.newInstance();
Participants participants = Participants.fromPeople(people);
LadderGame ladderGame = new LadderGame(participants, ladder, prizes);
outputView.printResult(ladderGame.getParticipants(), ladderGame.getLadder(), ladderGame.getPrizes());
ladderGame.start();
GameResult gameResult = ladderGame.getParticipantsPrizes();
printSpecificParticipantResult(ladderGame.getParticipants(), gameResult);
outputView.printParticipantsPrizesResult(ladderGame.getParticipants(), gameResult);
}
private List<Person> readParticipants() {
outputView.printParticipantInquiry();
List<Person> participants = inputView.readParticipants();
outputView.printEmptyLine();
return participants;
}
private List<Prize> readPrizes() {
outputView.printResultPrizeInquiry();
List<Prize> prizes = inputView.readPrizeResults();
outputView.printEmptyLine();
return prizes;
}
private int readLadderHeight() {
outputView.printLadderHeightInquiry();
int height = inputView.readLadderHeight();
outputView.printEmptyLine();
return height;
}
private String readParticipantName() {
outputView.printParticipantPrizeInquiry();
String name = inputView.readPersonName();
outputView.printEmptyLine();
return name;
}
private void printSpecificParticipantResult(Participants participants, GameResult gameResult) {
while (true) {
String name = readParticipantName();
if (name.equals("all")) {
break;
}
Person person = new Person(name);
Participant participant = participants.getParticipantByName(person);
outputView.printParticipantPrizeResult(gameResult.getPrize(participant));
}
}
private void validateInputsCount(int participantCount, int prizeCount) {
if (participantCount != prizeCount) {
throw new IllegalArgumentException("The number of participants does not match the number of prizes.");
}
}
}