-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridMapCell.java
More file actions
153 lines (127 loc) · 3.82 KB
/
Copy pathGridMapCell.java
File metadata and controls
153 lines (127 loc) · 3.82 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// public class for a cell in the GridMap
import java.util.ArrayList;
public class GridMapCell {
// private data members
private int r;
private int c;
private Entity entity;
private ArrayList<Unit> units = new ArrayList<Unit>();
// GridMapCell constructor
public GridMapCell(int r, int c, Entity entity) {
this.r = r;
this.c = c;
this.entity = entity;
}
// getter methods
public int getRow() {
return r;
}
public int getColumn() {
return c;
}
public Entity getEntity() {
return entity;
}
public int heroCount() {
int count = 0;
for (Unit unit : units) {
if (unit instanceof HeroEntity) {
count += 1;
}
}
return count;
}
public int enemyCount() {
int count = 0;
for (Unit unit : units) {
if (unit instanceof EnemyEntity) {
count += 1;
}
}
return count;
}
public EnemyEntity getEnemy(){
for (Unit unit: units){
if(unit instanceof EnemyEntity){
return (EnemyEntity) unit;
}
}
return null; //idk what to return if there is no enemy here (bc this should never be called if there's not enemy in the cell)
}
// setter methods
public void setLocation(int r, int c) {
this.r = r;
this.c = c;
}
public void setEntity(Entity entity) {
this.entity = entity;
}
// toString method
public String toString() {
String toUseColor = Colors.ANSI_BLUE;
if (this.entity instanceof Terrain) {
if (this.entity instanceof PlainTerrain){
toUseColor = Colors.ANSI_WHITE;
}
else if (this.entity instanceof BushTerrain){
toUseColor = Colors.ANSI_GREEN;
}
else if (this.entity instanceof CaveTerrain){
toUseColor = Colors.ANSI_YELLOW;
} else if (this.entity instanceof Nexus) {
if (((Nexus) this.entity).getType().equals("HERO")) {
toUseColor = Colors.ANSI_PURPLE;
} else {
toUseColor = Colors.ANSI_BLUE;
}
} else{
toUseColor = Colors.ANSI_CYAN;
}
} else if (this.entity instanceof InaccesibleTerrain) {
return Colors.ANSI_RED + "|" + Colors.ANSI_RED_BACKGROUND + " " + Colors.ANSI_RESET + Colors.ANSI_RED + "|" + Colors.ANSI_RESET;
} else {
toUseColor = Colors.ANSI_WHITE;
}
return toUseColor + "|" + cellContentPrintable() + "|" + Colors.ANSI_RESET;
}
// additional method
public boolean placeHero(HeroEntity hero) {
if (heroCount() == 0) {
units.add(hero);
return true;
} else {
return false;
}
}
public boolean placeEnemy(EnemyEntity enemy) {
if (enemyCount() == 0) {
units.add(enemy);
return true;
} else {
return false;
}
}
public void removeHero() {
for (int i = 0; i < units.size(); i++) {
if (units.get(i) instanceof HeroEntity) {
units.remove(i);
}
}
}
public void removeEnemy() {
for (int i = 0; i < units.size(); i++) {
if (units.get(i) instanceof EnemyEntity) {
units.remove(i);
}
}
}
public String cellContentPrintable() {
if (units.size() == 0) {
return " ";
} else if (units.size() == 1) {
return " " + units.get(0).getIndicator() + " ";
} else {
return units.get(0).getIndicator() + " " + units.get(1).getIndicator();
}
}
}