-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEnemy.java
More file actions
101 lines (87 loc) · 3.02 KB
/
Enemy.java
File metadata and controls
101 lines (87 loc) · 3.02 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
package projects.Pacman;
import info.gridworld.actor.Actor;
import info.gridworld.actor.Critter;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;
import java.util.ArrayList;
public class Enemy extends Critter {
//private Location prevLoc = getLocation();
public Enemy(){
}
public Location findPacMan() {
Location loc = new Location(0, 0);
ArrayList<Object> actors = getActorList();
for (Object a : actors) {
if (a instanceof Player) {
loc = ((Player) a).getLocation();
break;
}
}
return loc;
}
/*
public boolean isCollision(int direction) {
Grid gr = getGrid();
if(gr == null) {
return false;
} else {
Location loc = this.getLocation();
Location next = loc.getAdjacentLocation(direction);
if(!gr.isValid(next)) {
return false;
} else {
Actor neighbor = (Actor)gr.get(next);
return neighbor instanceof Enemy;
}
}
}
*/
public ArrayList<Object> getActorList() {
Location loc;
Grid gr = getGrid();
ArrayList<Object> actors = new ArrayList<Object>();
int x = gr.getNumCols() - 1;
int y = gr.getNumRows() - 1;
for (int count = 1; count < x; count++) {
for (int count_1 = 1; count_1 < y; count_1++) {
loc = new Location(count, count_1);
if (gr.isValid(loc))
if (gr.get(loc) != null) {
actors.add(gr.get(loc));
}
}
}
return actors;
}
public ArrayList<Location> getMoveLocations() {
ArrayList<Location> PossibleMoves = new ArrayList<Location>();
for (int degree = 0; degree < 360; degree += 90) {
if (this.getGrid().get(this.getLocation().getAdjacentLocation(degree)) instanceof Wall ||
this.getGrid().get(this.getLocation().getAdjacentLocation(degree)) instanceof Enemy) {
}
/*
else if(getGrid().get(getLocation().getAdjacentLocation(degree)).equals(prevLoc)) {
} */
else { PossibleMoves.add(this.getLocation().getAdjacentLocation(degree)); }
}
//prevLoc = getLocation();
return checkValidty(PossibleMoves);
}
public Location checkTeleport(Location chosen){
if(chosen.equals(new Location(9,0))) {
chosen = new Location(9,17);
}
else if(chosen.equals(new Location(9,18))) {
chosen = new Location(9,1);
}
return chosen;
}
public ArrayList<Location> checkValidty(ArrayList<Location> locs) {
for (Location location : locs) {
if (!getGrid().isValid(location)) {
locs.remove(location);
}
}
return locs;
}
}