-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathLadderExecutor.java
More file actions
34 lines (26 loc) · 1.01 KB
/
LadderExecutor.java
File metadata and controls
34 lines (26 loc) · 1.01 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
package nextstep.ladder.domain;
import engine.LinesCreator;
import java.util.Collections;
public class LadderExecutor {
private LinesCreator linesCreator;
private Participants participants;
public LadderExecutor(LinesCreator linesCreator, Participants participants) {
this.linesCreator = linesCreator;
this.participants = participants;
}
public MachingResult play() {
MachingResult results = new MachingResult(Collections.emptyMap());
for (int i = 0; i < participants.size(); i++) {
Position position = new Position(i, 0);
moveAndCollectResult(results, position);
}
return results;
}
private void moveAndCollectResult(MachingResult results, Position position) {
for (Line line : linesCreator.getLines()) {
Point point = PointFactory.generatePoint(position.getX(), line);
position.move(point.getDirection());
}
results.addResult(position.getInitialX(), position.getX());
}
}