-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoopBlockDecorator.java
More file actions
93 lines (86 loc) · 3.5 KB
/
Copy pathLoopBlockDecorator.java
File metadata and controls
93 lines (86 loc) · 3.5 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.awt.*;
public class LoopBlockDecorator extends Block{
protected Block decoratedBlock;
private int x_len = 70, y_len = 15;
public LoopBlockDecorator(Block decoratedBlock,int x1, int y1){
this.decoratedBlock = decoratedBlock;
super.setName("Loop Block");
super.setX1(x1);
super.setX2(x1 + x_len);
super.setY1(y1);
super.setY2(y1 + y_len);
super.setColor(Color.MAGENTA);
}
public LoopBlockDecorator(int x1, int y1){
super.setName("Loop Block");
super.setX1(x1);
super.setX2(x1 + x_len);
super.setY1(y1);
super.setY2(y1 + y_len);
super.setColor(Color.MAGENTA);
}
public void draw(Graphics g){
g.setColor(super.getColor());
g.fillRect(super.getX1(), super.getY1(), x_len, y_len);
g.setColor(Color.black);
g.drawString(super.getName(), super.getX1(), super.getY1() + 10);
}
public void add(Block b){
decoratedBlock = b;
}
public void connect(){
int x_avg = (super.getX1()+super.getX2())/2;
Block temp, temp2, transfer;
boolean first, reconnecting = false;
if(DataSource.getInstance().getBlocksRunInstance().contains(this)){first = true;}else{first = false;}
for(int i = 0; i < DataSource.getInstance().getBlockArrayInstance().size(); i++){
temp = DataSource.getInstance().getBlockArrayInstance().get(i);
if(this == temp){continue;}
do{
if((this.getY1() >= temp.getY2() - 5 && super.getY1() <= temp.getY2() + 5) && (x_avg >= temp.getX1() && x_avg <= temp.getX2())){
DataSource.getInstance().getBlocksRunInstance().remove(this);
this.setY1(temp.getY2());
this.setX1(temp.getX1());
this.setX2(temp.getX2());
this.setY2(this.getY1()+y_len);
Block shift_temp = this.decoratedBlock;
int y_temp = this.getY1() + y_len;
while(shift_temp != null){
shift_temp.setY1(y_temp);
shift_temp.setX1(temp.getX1());
y_temp += y_len;
shift_temp = shift_temp.next;
}
if(temp.next != this) {
Block anchor;
anchor = this;
while(anchor.next != null){anchor = anchor.next;}
transfer = temp.next;
this.prev = temp;
temp.next = this;
anchor.next = transfer;
temp2 = transfer;
do {
if (temp2 != null) {
temp2.shift(y_len);
temp2.setX1(temp.getX1());
temp2 = temp2.next;
}
} while (temp2 != null);
}else{reconnecting = true;}
if(DataSource.getInstance().getBlocksRunInstance().contains(this)){
first = true;
}
break;
}
temp = temp.next;
}while(temp != null);
}
if(!first && !reconnecting){
System.out.println("hit");
prev.next = null;
prev = null;
DataSource.getInstance().getBlocksRunInstance().add(this);
}
}
}