Make getNeighbors function static

This commit is contained in:
drdev
2015-11-29 18:31:30 +00:00
parent dc07388120
commit 467899750a
2 changed files with 20 additions and 14 deletions

View File

@@ -14,6 +14,7 @@ import forge.card.CardDetailUtil.DetailColors;
import forge.model.FModel;
import forge.planarconquest.ConquestData;
import forge.planarconquest.ConquestLocation;
import forge.planarconquest.ConquestPlane;
import forge.planarconquest.ConquestPlane.Region;
import forge.planarconquest.ConquestPlaneData;
import forge.screens.FScreen;
@@ -81,6 +82,10 @@ public class ConquestMapScreen extends FScreen {
int rows = Region.ROWS_PER_REGION;
float colWidth = w / cols;
float rowHeight = regionHeight / rows;
ConquestPlane plane = model.getCurrentPlane();
FCollectionView<Region> regions = plane.getRegions();
int regionCount = regions.size();
ConquestPlaneData planeData = model.getCurrentPlaneData();
ConquestLocation currentLocation = model.getCurrentLocation();
@@ -91,8 +96,6 @@ public class ConquestMapScreen extends FScreen {
float y = -getScrollTop();
float colLineStartY = 0;
float colLineEndY = h;
FCollectionView<Region> regions = model.getCurrentPlane().getRegions();
int regionCount = regions.size();
//draw top portal row
if (y + rowHeight > 0) {
@@ -148,7 +151,7 @@ public class ConquestMapScreen extends FScreen {
color = FOG_OF_WAR_COLOR;
//if any bordering grid square has been conquered, instead show unconquered color
for (ConquestLocation loc : currentLocation.getNeighbors(i, r, c)) {
for (ConquestLocation loc : ConquestLocation.getNeighbors(plane, i, r, c)) {
if (planeData.getEventResult(loc.getRegionIndex(), loc.getRow(), loc.getCol()) > 0) {
color = UNCONQUERED_COLOR;
break;
@@ -184,6 +187,8 @@ public class ConquestMapScreen extends FScreen {
x0 += colWidth;
}
//draw planeswalker avatar
g.endClip();
}

View File

@@ -53,41 +53,42 @@ public class ConquestLocation {
}
public List<ConquestLocation> getNeighbors() {
return getNeighbors(regionIndex, row, col);
return getNeighbors(plane, regionIndex, row, col);
}
public List<ConquestLocation> getNeighbors(int regionIndex0, int row0, int col0) {
int regionCount = plane.getRegions().size();
public static List<ConquestLocation> getNeighbors(ConquestPlane plane0, int regionIndex0, int row0, int col0) {
int regionCount = plane0.getRegions().size();
List<ConquestLocation> locations = new ArrayList<ConquestLocation>();
//add location above
if (row0 < Region.ROWS_PER_REGION - 1) {
locations.add(new ConquestLocation(plane, regionIndex0, row0 + 1, col0));
locations.add(new ConquestLocation(plane0, regionIndex0, row0 + 1, col0));
}
else if (regionIndex0 < regionCount - 1) {
locations.add(new ConquestLocation(plane, regionIndex0 + 1, 0, col0));
locations.add(new ConquestLocation(plane0, regionIndex0 + 1, 0, col0));
}
else if (regionIndex0 == regionCount - 1 && col0 == Region.PORTAL_COL) {
locations.add(new ConquestLocation(plane, regionCount, 0, col0));
locations.add(new ConquestLocation(plane0, regionCount, 0, col0));
}
//add location below
if (row0 > 0) {
locations.add(new ConquestLocation(plane, regionIndex0, row0 - 1, col0));
locations.add(new ConquestLocation(plane0, regionIndex0, row0 - 1, col0));
}
else if (regionIndex0 > 0) {
locations.add(new ConquestLocation(plane, regionIndex0 - 1, Region.ROWS_PER_REGION - 1, col0));
locations.add(new ConquestLocation(plane0, regionIndex0 - 1, Region.ROWS_PER_REGION - 1, col0));
}
else if (regionIndex0 == 0 && col0 == Region.PORTAL_COL) {
locations.add(new ConquestLocation(plane, -1, 0, col0));
locations.add(new ConquestLocation(plane0, -1, 0, col0));
}
//add locations left and right
if (regionIndex0 >= 0 && regionIndex0 < regionCount) { //not options in portal row
if (col0 > 0) {
locations.add(new ConquestLocation(plane, regionIndex0, row0, col0 - 1));
locations.add(new ConquestLocation(plane0, regionIndex0, row0, col0 - 1));
}
if (col0 < Region.COLS_PER_REGION - 1) {
locations.add(new ConquestLocation(plane, regionIndex0, row0, col0 + 1));
locations.add(new ConquestLocation(plane0, regionIndex0, row0, col0 + 1));
}
}