-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathLine.java
More file actions
59 lines (47 loc) · 1.52 KB
/
Line.java
File metadata and controls
59 lines (47 loc) · 1.52 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package nextstep.ladder;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class Line {
private static final Random RANDOM = new Random();
private static final String LINE_DELIMITER = "|";
private List<Cross> crosses;
public Line(int countOfPerson) {
createCrosses(countOfPerson);
}
public Line(List<Cross> crosses) {
this.crosses = crosses;
}
private void createCrosses(int countOfPerson) {
crosses = new ArrayList<>();
Point point = Point.first(RANDOM.nextBoolean());
for (int i = 0; i < countOfPerson; i++) {
point = updatePoint(i, countOfPerson, point);
crosses.add(new Cross(i, point));
}
}
private Point updatePoint(int index, int countOfPerson, Point currentPoint) {
if (index == countOfPerson - 1) {
return currentPoint.last();
}
if (index > 0) {
return currentPoint.next(RANDOM.nextBoolean());
}
return currentPoint;
}
//todo
public int move(int position) {
return this.crosses.get(position).move();
}
//todo
public int getCrossSize() {
return crosses.size();
}
public String getLineForPrint(String trueSymbol, String falseSymbol) {
return LINE_DELIMITER
+ crosses.stream()
.map(cross -> cross.getCrossForPrint(trueSymbol, falseSymbol))
.collect(Collectors.joining(LINE_DELIMITER));
}
}