Merge branch 'master' of github.com:jokerx3/prp

This commit is contained in:
andreas
2014-11-04 15:23:21 +01:00
4 changed files with 127 additions and 2 deletions
@@ -0,0 +1,25 @@
package de.heatup.mapengine;
public class GridCell {
private boolean isPath = false;
private boolean isTrigger = false;
private char correspondingHardwareToTrigger;
public char getCorrespondingHardwareToTrigger() {
return correspondingHardwareToTrigger;
}
public void setCorrespondingHardwareToTrigger(char correspondingHardwareToTrigger) {
this.correspondingHardwareToTrigger = correspondingHardwareToTrigger;
}
public boolean isPath() {
return isPath;
}
protected void setPath(boolean isPath) {
this.isPath = isPath;
}
public boolean isTrigger() {
return isTrigger;
}
protected void setTrigger(boolean isTrigger) {
this.isTrigger = isTrigger;
}
}
@@ -56,6 +56,58 @@ public class MapEngine {
while (input.hasNextLine() && lineCount <= mapHeight) {
String currentLine = input.nextLine();
for (int i = 0; i<mapWidth; i++) {
/* MapGrid implementation */
if (checkIfPath(currentLine.charAt(i))) {
if (MapGrid.getGridCell(i, lineCount) == null) {
MapGrid.addGrid(i, lineCount, true);
} else {
MapGrid.getGridCell(i, lineCount).setPath(true);
}
} else {
if (checkIfHardware(currentLine.charAt(i))) {
if (MapGrid.getGridCell(i, lineCount) == null) {
MapGrid.addGrid(i, lineCount, false);
} else {
MapGrid.getGridCell(i, lineCount).setPath(false);
}
/* trigger setzen */
/* trigger 1 */
if (MapGrid.getGridCell(i+1, lineCount) == null) {
MapGrid.addGrid(i+1, lineCount, true, currentLine.charAt(i));
} else {
MapGrid.getGridCell(i+1, lineCount).setTrigger(true);
MapGrid.getGridCell(i+1, lineCount).setCorrespondingHardwareToTrigger(currentLine.charAt(i));
}
/* trigger 2 */
if (MapGrid.getGridCell(i-1, lineCount) == null) {
MapGrid.addGrid(i-1, lineCount, true, currentLine.charAt(i));
} else {
MapGrid.getGridCell(i-1, lineCount).setTrigger(true);
MapGrid.getGridCell(i-1, lineCount).setCorrespondingHardwareToTrigger(currentLine.charAt(i));
}
/* trigger 3 */
if (MapGrid.getGridCell(i, lineCount+1) == null) {
MapGrid.addGrid(i, lineCount+1, true, currentLine.charAt(i));
} else {
MapGrid.getGridCell(i, lineCount+1).setTrigger(true);
MapGrid.getGridCell(i, lineCount+1).setCorrespondingHardwareToTrigger(currentLine.charAt(i));
}
/* trigger 4 */
if (MapGrid.getGridCell(i, lineCount-1) == null) {
MapGrid.addGrid(i, lineCount-1, true, currentLine.charAt(i));
} else {
MapGrid.getGridCell(i, lineCount-1).setTrigger(true);
MapGrid.getGridCell(i, lineCount-1).setCorrespondingHardwareToTrigger(currentLine.charAt(i));
}
} else {
if (MapGrid.getGridCell(i, lineCount) == null) {
MapGrid.addGrid(i, lineCount, false);
} else {
MapGrid.getGridCell(i, lineCount).setPath(false);
}
}
}
/* End of MapGrid implementation */
if (!allMapTiles.containsKey(currentLine.charAt(i))) {
ArrayList<Point> newTileType = new ArrayList<Point>();
newTileType.add(new Point(x,y));
@@ -140,4 +192,15 @@ public class MapEngine {
public ArrayList<StaticObject> getAllHardwareTriggerObjects() {
return MapObjectHandler.getAllHardwareTriggerObjects();
}
private boolean checkIfPath(char c) {
return (c=='#');
}
private boolean checkIfHardware(char c) {
for (char j = '0'; j <= '9'; j++) {
if (j==c) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,38 @@
package de.heatup.mapengine;
import de.heatup.cfg.Config;
public class MapGrid {
private static GridCell[][] allGridCells = new GridCell[Config.mapMaxTilesWidth][Config.mapMaxTilesHeight];
private static GridCell dummyCell = new GridCell(); // wird zurückgegeben, falls der MapGrid index ausserhalb unserer allGridCells dimension zeigt.
protected static void addGrid(int x, int y, boolean isPath) {
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) {
GridCell newCell = new GridCell();
newCell.setPath(isPath);
allGridCells[x][y] = newCell;
}
}
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)) {
GridCell newCell = new GridCell();
newCell.setPath(isPath);
newCell.setTrigger(isTrigger);
newCell.setCorrespondingHardwareToTrigger(correspondingHardwareToTrigger);
allGridCells[x][y] = newCell;
}
}
protected static void addGrid(int x, int y, boolean isTrigger, char correspondingHardwareToTrigger) {
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) {
GridCell newCell = new GridCell();
newCell.setTrigger(isTrigger);
newCell.setCorrespondingHardwareToTrigger(correspondingHardwareToTrigger);
allGridCells[x][y] = newCell;
}
}
public static GridCell getGridCell(int x, int y) {
if (!(x < 0 || x > Config.mapMaxTilesWidth || y < 0 || y > Config.mapMaxTilesHeight)) {
return allGridCells[x][y];
}
return dummyCell;
}
}
@@ -4,7 +4,6 @@ import java.awt.Point;
import java.util.ArrayList;
import de.heatup.cfg.Config;
import de.heatup.logging.Logger;
import de.heatup.objects.StaticObject;
public class MapObjectHandler {
@@ -41,7 +40,7 @@ public class MapObjectHandler {
Point currentTriggerTilesFirstPoint = new Point(firstPoint.x-(triggerAreaAddition/2),firstPoint.y-(triggerAreaAddition/2));
StaticObject newStaticObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight);
// Trigger Object
// Trigger Object - auskommentieren sobald implementiert.
// StaticObject newTriggerObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight, true);
MapObjectHandler.allMapObjects.add(newStaticObject);
// MapObjectHandler.allMapObjects.add(newTriggerObject);