-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.java
More file actions
78 lines (62 loc) · 1.72 KB
/
Entity.java
File metadata and controls
78 lines (62 loc) · 1.72 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
import java.awt.Color;
public class Entity {
private int row;
private int col;
private boolean infected;
private boolean immune;
public Entity(int row, int col) {
this.row = row;
this.col = col;
this.infected = false;
this.immune = false;
}
public void setRow(int row) {
this.row = row;
}
public void setCol(int col) {
this.col = col;
}
public void setInfected(boolean infected) {
this.infected = infected;
}
public void setImmune(boolean immune) {
this.immune = immune;
}
public void move(Entity[][] grid) {
}
public void interact(Entity[][] grid) {
}
public Color getColor() {
return Color.WHITE;
}
public boolean isInfected() {
return infected;
}
public boolean isImmune() {
return immune;
}
public int getRow() {
return row;
}
public int getCol() {
return col;
}
public Entity[][] getNeighbors(Entity[][] grid) {
Entity[][] neighbors = new Entity[3][3];
for (int r = -1; r <= 1; r++) {
for (int c = -1; c <= 1; c++) {
int newRow = row + r;
int newCol = col + c;
if (isInBounds(newRow, newCol, grid)) {
neighbors[r + 1][c + 1] = grid[newRow][newCol];
} else {
neighbors[r + 1][c + 1] = null;
}
}
}
return neighbors;
}
public boolean isInBounds(int r, int c, Entity[][] grid) {
return r >= 0 && r < grid.length && c >= 0 && c < grid[0].length;
}
}