Skip to content

Commit 9d90f0a

Browse files
committed
implement Region
1 parent 386d226 commit 9d90f0a

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

src/main/java/bwapi/Game.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414

1515
public class Game {
1616
final GameData gameData;
17-
final Map<Integer, Unit> units = new HashMap<>();
17+
18+
///CONSTANT
1819
final Map<Integer, Player> players = new HashMap<>();
20+
final Map<Integer, Region> regions = new HashMap<>();
1921
final Map<Integer, Force> forces = new HashMap<>();
22+
23+
//CHANGING
24+
final Map<Integer, Unit> units = new HashMap<>();
25+
2026
final Map<Integer, Bullet> bullets = new HashMap<>();
2127

2228
public Game(GameData gameData) {
@@ -31,6 +37,9 @@ private void init() {
3137
for (int id=0; id < gameData.getPlayerCount(); id++) {
3238
players.put(id, new Player(gameData.getPlayer(id), this));
3339
}
40+
for (int id=0; id < gameData.regionCount(); id++) {
41+
regions.put(id, new Region(gameData.getRegion(id), this));
42+
}
3443
}
3544

3645
public Collection<Force> getForces() {
@@ -73,23 +82,27 @@ public Collection<Bullet> getBullets() {
7382
public List<Position> getNukeDots();
7483
*/
7584

76-
public Force getForce(int forceID) {
85+
public Force getForce(final int forceID) {
7786
return forces.get(forceID);
7887
}
7988

80-
public Player getPlayer(int playerID) {
89+
public Player getPlayer(final int playerID) {
8190
return players.get(playerID);
8291
}
8392

84-
public Unit getUnit(int unitID) {
93+
public Unit getUnit(final int unitID) {
8594
return units.get(unitID);
8695
}
8796
/*
8897
8998
public Unit indexToUnit(int unitIndex);
9099
91-
public Region getRegion(int regionID);
100+
*/
101+
public Region getRegion(final int regionID) {
102+
return regions.get(regionID);
103+
}
92104

105+
/*
93106
public GameType getGameType() ;
94107
95108
public int getLatency();
@@ -477,8 +490,12 @@ public Player neutral() {
477490
478491
public int countdownTimer();
479492
480-
public List<Region> getAllRegions();
493+
*/
494+
public Collection<Region> getAllRegions() {
495+
return regions.values();
496+
}
481497

498+
/*
482499
public Region getRegionAt(int x, int y);
483500
484501
public Region getRegionAt(Position position);

src/main/java/bwapi/Region.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,84 @@
22

33
import bwapi.point.Position;
44

5-
import java.util.Map;
6-
import java.util.HashMap;
5+
import JavaBWAPIBackend.Client.GameData.RegionData;
6+
77
import java.util.List;
88

99
public class Region {
10-
private final int id;
10+
private final RegionData regionData;
11+
private final Game game;
1112

12-
Region(int id) {
13-
this.id = id;
13+
Region(final RegionData regionData, final Game game) {
14+
this.regionData = regionData;
15+
this.game = game;
1416
}
1517

1618
public int getID() {
17-
return id;
19+
return regionData.id();
1820
}
1921

2022
public int getRegionGroupID() {
21-
return -1;
23+
return regionData.islandID();
2224
}
2325

2426
public Position getCenter() {
25-
return null;
27+
return new Position(regionData.centerX(), regionData.centerY());
2628
}
2729

2830
public boolean isHigherGround() {
29-
return false;
31+
return regionData.isHigherGround();
3032
}
3133

3234
public int getDefensePriority() {
33-
return -1;
35+
return regionData.priority();
3436
}
3537

3638
public boolean isAccessible() {
37-
return false;
39+
return regionData.isAccessible();
3840
}
3941

42+
//TODO
4043
public List<Region> getNeighbors() {
4144
return null;
4245
}
4346

4447
public int getBoundsLeft() {
45-
return -1;
48+
return regionData.leftMost();
4649
}
4750

4851
public int getBoundsTop() {
49-
return -1;
52+
return regionData.topMost();
5053
}
5154

5255
public int getBoundsRight() {
53-
return -1;
56+
return regionData.rightMost();
5457
}
5558

5659
public int getBoundsBottom() {
57-
return -1;
60+
return regionData.bottomMost();
5861
}
5962

63+
//TODO
6064
public Region getClosestAccessibleRegion() {
6165
return null;
6266
}
6367

68+
//TODO
6469
public Region getClosestInaccessibleRegion() {
6570
return null;
6671
}
6772

73+
//TODO
6874
public int getDistance(Region other) {
6975
return -1;
7076
}
7177

78+
//TODO
7279
public List<Unit> getUnits() {
7380
return null;
7481
}
7582

76-
7783
public boolean equals(Object that){
7884
if(!(that instanceof Region)){
7985
return false;

0 commit comments

Comments
 (0)