-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.java
More file actions
88 lines (78 loc) · 2.28 KB
/
Copy pathTile.java
File metadata and controls
88 lines (78 loc) · 2.28 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Tile here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Tile extends Actor
{
private Tetromino parent;
public Tile(Tetromino initParent) {
String color;
switch (initParent.getType()) {
// O
case 0: color = "yellow";
break;
// I
case 1: color = "lightblue";
break;
// Z
case 2: color = "red";
break;
// S
case 3: color = "green";
break;
// T
case 4: color = "purple";
break;
// L
case 5: color = "orange";
break;
// J
case 6: color = "darkblue";
break;
default: color = "red";
break;
}
setImage(color + ".png");
parent = initParent;
}
public void move(String direction) {
if (direction.equals("left")) {
setLocation(getX()-1, getY());
if (borderCheck() || tileCheck()) {
parent.moveAll("right");
}
} else if (direction.equals("right")) {
setLocation(getX()+1, getY());
if (borderCheck() || tileCheck()) {
parent.moveAll("left");
}
}
}
public boolean borderCheck() {
return getIntersectingObjects(Border.class).size() > 0 && !getIntersectingObjects(Border.class).get(0).isPassable();
}
public boolean tileCheck() {
return getIntersectingObjects(Tile.class).size() > 0 && getIntersectingObjects(Tile.class).get(0).isSolid();
}
public void fall() {
setLocation(getX(), getY()+1);
if (borderCheck()) {
parent.solidify(true);
}
if (tileCheck()) {
parent.solidify(true);
}
}
public void remove() {
getWorld().removeObject(this);
}
public boolean isSolid() {
return parent.isSolid();
}
public boolean isActive() {
return parent.isActive();
}
}