-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathActionBlock.java
More file actions
105 lines (100 loc) · 4.22 KB
/
Copy pathActionBlock.java
File metadata and controls
105 lines (100 loc) · 4.22 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
94
95
96
97
98
99
100
101
102
103
104
105
import javax.swing.*;
import javax.xml.crypto.Data;
import java.awt.*;
public class ActionBlock extends Block{
private int x_len = 70, y_len = 15;
public ActionBlock(int x1, int y1, String action){
super.setX1(x1);
super.setX2(x1 + x_len);
super.setY1(y1);
super.setY2(y1 + y_len);
switch(action){
case "Step": super.setName("Step");
super.setColor(Color.GRAY);
break;
case "Turn": super.setName("Turn");
super.setColor(Color.GRAY);
break;
case "Paint Red": super.setName("Paint Red");
super.setColor(Color.RED);
break;
case "Paint Blue": super.setName("Paint Blue");
super.setColor(Color.BLUE);
break;
case "Paint Green": super.setName("Paint Green");
super.setColor(Color.GREEN);
break;
}
}
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 connect(){
int x_avg = (super.getX1()+super.getX2())/2;
Block temp, temp2, transfer;
boolean first, reconnecting = false, connectingToLoopBlock = 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);
if(temp.getName() == "Loop Block"){
((LoopBlockDecorator)temp).add(this);
connectingToLoopBlock = true;
}
this.setY1(temp.getY2());
this.setX1(temp.getX1());
this.setX2(temp.getX2());
this.setY2(this.getY1()+y_len);
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;}
Block shift_temp;
shift_temp = this.next;
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(DataSource.getInstance().getBlocksRunInstance().contains(this)){
first = true;
}
break;
}
temp = temp.next;
}while(temp != null);
}
if(!first && !reconnecting){
if(prev != null) {
if (prev.getName() == "Loop Block") {
((LoopBlockDecorator) prev).decoratedBlock = null;
} else {
prev.next = null;
}
prev = null;
}
DataSource.getInstance().getBlocksRunInstance().add(this);
}
}
}