-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathLine.java
More file actions
42 lines (32 loc) · 1.1 KB
/
Line.java
File metadata and controls
42 lines (32 loc) · 1.1 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
package model;
import java.util.List;
import java.util.stream.IntStream;
public class Line {
private final List<Point> points;
public Line(List<Point> points) {
this.points = List.copyOf(points);
}
public static List<Line> createLines(int playerCount, int maxHeight, PointGenerator pointGenerator) {
return IntStream.range(0, maxHeight)
.mapToObj(i -> new Line(pointGenerator.createLinePoints(new Size(playerCount))))
.toList();
}
public int move(int position) {
if(canMoveLeft(position)) {
return position -1;
}
if(canMoveRight(position)) {
return position + 1;
}
return position;
}
private boolean canMoveLeft(int position) {
return position > 0 && points.get(position - 1) == Point.HAS_POINT;
}
private boolean canMoveRight(int position) {
return position < points.size() && points.get(position) == Point.HAS_POINT;
}
public List<Point> getPointGroups() {
return List.copyOf(points);
}
}