-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathLadder.java
57 lines (45 loc) · 1.49 KB
/
Ladder.java
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
package domain;
import java.util.ArrayList;
import java.util.List;
public class Ladder {
private final List<Line> lines;
public Ladder(Size ladderSize, Size lineSize) {
this.lines = generateLines(ladderSize, lineSize);
}
public Ladder(List<Line> lines) {
this.lines = lines;
}
private List<Line> generateLines(Size ladderSize, Size lineSize) {
List<Line> lines = new ArrayList<>();
for (int i = 0; i < ladderSize.getSize(); i++) {
lines.add(new Line(lineSize));
}
return lines;
}
public void getResult(Participants participants){
for (Line line : lines) {
changeByLine(line, participants.getParticipants());
}
}
private void changeByLine(Line line, List<Participant> participants){
for(int i = 0; i< line.getPoints().size() ; i++){
changeByPoint(i,line.getPoints().get(i), participants);
}
}
private void changeByPoint(int idx, Point point, List<Participant> participants){
if(point.isConnected()){
move(idx, participants);
}
}
private void move(int idx, List<Participant> participants){
int temp = participants.get(idx).getEnd();
participants.get(idx).changeEnd(participants.get(idx+1).getEnd());
participants.get(idx+1).changeEnd(temp);
}
public List<Line> getLines() {
return lines;
}
public int getWidth() {
return lines.get(0).getPoints().size()+1;
}
}