-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathLadderFactory.java
More file actions
33 lines (28 loc) · 894 Bytes
/
LadderFactory.java
File metadata and controls
33 lines (28 loc) · 894 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
package model;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class LadderFactory {
private final Random random = new Random();
public Ladder create(LadderSize size, int width) {
List<Line> lines = new ArrayList<>();
for (int i = 0; i < size.height(); i++) {
lines.add(createLine(width));
}
return new Ladder(lines);
}
private Line createLine(int width) {
int pointsCount = width - 1;
List<Point> points = new ArrayList<>();
boolean prevConnected = false;
for (int i = 0; i < pointsCount; i++) {
boolean connect = false;
if (!prevConnected) {
connect = random.nextBoolean();
}
points.add(new Point(connect));
prevConnected = connect;
}
return new Line(points);
}
}