Bugfix MapGrid.

Methode zur Ausgabe des MapGrids inklusive Triggerzonen
This commit is contained in:
toksikk
2014-11-05 10:42:15 +01:00
parent 2668fe8c3f
commit 9114d0d2c3
4 changed files with 30 additions and 12 deletions
@@ -203,4 +203,22 @@ public class MapEngine {
} }
return false; return false;
} }
public void printMapGridWithTriggers() {
for (int i = 0; i < 24; i++) {
for (int j = 0; j < 32; j++) {
if (!MapGrid.getGridCell(j, i).isPath() && !MapGrid.getGridCell(j, i).isTrigger()) {
System.out.print("-");
} else {
if (MapGrid.getGridCell(j, i).isTrigger()) {
System.out.print(MapGrid.getGridCell(j, i).getCorrespondingHardwareToTrigger()+"");
}
if (MapGrid.getGridCell(j, i).isPath() && !MapGrid.getGridCell(j, i).isTrigger()) {
System.out.print("#");
}
}
}
System.out.println();
}
}
} }
+7 -7
View File
@@ -3,18 +3,18 @@ package de.heatup.mapengine;
import de.heatup.cfg.Config; import de.heatup.cfg.Config;
public class MapGrid { public class MapGrid {
private static GridCell[][] allGridCells = new GridCell[Config.mapMaxTilesWidth][Config.mapMaxTilesHeight]; private static MapGridCell[][] allGridCells = new MapGridCell[Config.mapMaxTilesWidth][Config.mapMaxTilesHeight];
private static GridCell dummyCell = new GridCell(); // wird zurückgegeben, falls der MapGrid index ausserhalb unserer allGridCells dimension zeigt. private static MapGridCell dummyCell = new MapGridCell(); // wird zurückgegeben, falls der MapGrid index ausserhalb unserer allGridCells dimension zeigt.
protected static void addGrid(int x, int y, boolean isPath) { protected static void addGrid(int x, int y, boolean isPath) {
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) { if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) {
GridCell newCell = new GridCell(); MapGridCell newCell = new MapGridCell();
newCell.setPath(isPath); newCell.setPath(isPath);
allGridCells[x][y] = newCell; allGridCells[x][y] = newCell;
} }
} }
protected static void addGrid(int x, int y, boolean isPath, boolean isTrigger, char correspondingHardwareToTrigger) { protected static void addGrid(int x, int y, boolean isPath, boolean isTrigger, char correspondingHardwareToTrigger) {
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) { if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) {
GridCell newCell = new GridCell(); MapGridCell newCell = new MapGridCell();
newCell.setPath(isPath); newCell.setPath(isPath);
newCell.setTrigger(isTrigger); newCell.setTrigger(isTrigger);
newCell.setCorrespondingHardwareToTrigger(correspondingHardwareToTrigger); newCell.setCorrespondingHardwareToTrigger(correspondingHardwareToTrigger);
@@ -23,14 +23,14 @@ public class MapGrid {
} }
protected static void addGrid(int x, int y, boolean isTrigger, char correspondingHardwareToTrigger) { protected static void addGrid(int x, int y, boolean isTrigger, char correspondingHardwareToTrigger) {
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) { if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) {
GridCell newCell = new GridCell(); MapGridCell newCell = new MapGridCell();
newCell.setTrigger(isTrigger); newCell.setTrigger(isTrigger);
newCell.setCorrespondingHardwareToTrigger(correspondingHardwareToTrigger); newCell.setCorrespondingHardwareToTrigger(correspondingHardwareToTrigger);
allGridCells[x][y] = newCell; allGridCells[x][y] = newCell;
} }
} }
public static GridCell getGridCell(int x, int y) { public static MapGridCell getGridCell(int x, int y) {
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) { if (!(x < 0 || x > Config.mapMaxTilesWidth-1 || y < 0 || y > Config.mapMaxTilesHeight-1)) {
return allGridCells[x][y]; return allGridCells[x][y];
} }
return dummyCell; return dummyCell;
@@ -1,6 +1,6 @@
package de.heatup.mapengine; package de.heatup.mapengine;
public class GridCell { public class MapGridCell {
private boolean isPath = false; private boolean isPath = false;
private boolean isTrigger = false; private boolean isTrigger = false;
private char correspondingHardwareToTrigger; private char correspondingHardwareToTrigger;
+4 -4
View File
@@ -1,4 +1,4 @@
################################ ###1111#########################
#--1111----#----------#222222--# #--1111----#----------#222222--#
#--1111----#----------#222222--# #--1111----#----------#222222--#
#######################222222### #######################222222###
@@ -19,6 +19,6 @@
-666#---#-###---####-####--#-##- -666#---#-###---####-####--#-##-
-666#---#---#-###777-#--##----#- -666#---#---#-###777-#--##----#-
-666#####---###-#777-#---####### -666#####---###-#777-#---#######
----#-------#---##########88888# ----#-------#---##########888888
---##########------#------88888# ---##########------#------888888
------------#################### ------------####################