-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathLadder.java
More file actions
36 lines (29 loc) · 943 Bytes
/
Ladder.java
File metadata and controls
36 lines (29 loc) · 943 Bytes
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
package model;
import java.util.ArrayList;
import java.util.List;
public class Ladder {
private final List<Line> lines;
public Ladder(List<Line> lines) {
this.lines = List.copyOf(lines);
}
public static Ladder createLadder(int playerCount, int maxHeight, PointGenerator pointGenerator) {
List<Line> lines = Line.createLines(playerCount, maxHeight, pointGenerator);
return new Ladder(lines);
}
public int move(int position) {
for (Line line : lines) {
position = line.move(position);
}
return position;
}
public List<Point> getPointsFromLines() {
List<Point> result = new ArrayList<>();
for (Line line : lines) {
result.addAll(line.getPointGroups());
}
return List.copyOf(result);
}
public List<Line> getLines() {
return List.copyOf(lines);
}
}