Repository navigation
Expand file tree
/
Copy pathAsteroid.java
More file actions
59 lines (52 loc) · 1.9 KB
/
Copy pathAsteroid.java
File metadata and controls
59 lines (52 loc) · 1.9 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
public class Asteroid extends GameObject
{
private int size;
public Asteroid(Grid grid, Location loc, int size)
{
super(grid, loc, size * 25, size * 20);
this.size = size;
}
public boolean canMove(Location loc)
{
if(this.getGrid().isValidLocation(this.getGrid().getAdjacentLocationTowards(this.getObjLocation(), new Direction(Direction.DOWN))))
{
return true;
}
return false;
}
public void split()
{
Location right = this.getGrid().getAdjacentLocationTowards(this.getObjLocation(), new Direction(Direction.RIGHT));
Location left = this.getGrid().getAdjacentLocationTowards(this.getObjLocation(), new Direction(Direction.LEFT));
if(this.getGrid().isValidLocation(right) && this.getGrid().isValidLocation(left) && right.getObj() == null && left.getObj() == null)
{
Asteroid a1 = new Asteroid(this.getGrid(), right, this.size - 1);
Asteroid a2 = new Asteroid(this.getGrid(), left, this.size - 1);
a1.putSelfInGrid();
a2.putSelfInGrid();
this.removeSelfFromGrid();
}
else if((right.getObj() != null || !getGrid().isValidLocation(right)) && this.getGrid().isValidLocation(left) && left.getObj() == null)
{
Asteroid a1 = new Asteroid(this.getGrid(), left, this.size - 1);
Asteroid a2 = new Asteroid(this.getGrid(), this.getObjLocation(), this.size - 1);
a1.putSelfInGrid();
a2.putSelfInGrid();
//this.removeSelfFromGrid();
}
else if((left.getObj() != null || !getGrid().isValidLocation(left)) && this.getGrid().isValidLocation(right) && right.getObj() == null)
{
Asteroid a1 = new Asteroid(this.getGrid(), right, this.size - 1);
Asteroid a2 = new Asteroid(this.getGrid(), this.getObjLocation(), this.size - 1);
a1.putSelfInGrid();
a2.putSelfInGrid();
//this.removeSelfFromGrid();
}
else
{
Asteroid a1 = new Asteroid(this.getGrid(), this.getObjLocation(), this.size - 1);
a1.putSelfInGrid();
//this.removeSelfFromGrid();
}
}
}