mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:29:46 +02:00
Alte Methoden entfernt. Code aufgeräumt.
This commit is contained in:
@@ -18,8 +18,11 @@ import de.heatup.objects.*;
|
|||||||
public class MapEngine {
|
public class MapEngine {
|
||||||
|
|
||||||
private static final int singleTileWidth = Config.singleTilePixels;
|
private static final int singleTileWidth = Config.singleTilePixels;
|
||||||
|
|
||||||
private final int mapHeight = Config.mapMaxTilesHeight;
|
private final int mapHeight = Config.mapMaxTilesHeight;
|
||||||
|
|
||||||
private final int mapWidth = Config.mapMaxTilesWidth;
|
private final int mapWidth = Config.mapMaxTilesWidth;
|
||||||
|
|
||||||
private final int gamePanelWidth = Config.gamePanelWidth;
|
private final int gamePanelWidth = Config.gamePanelWidth;
|
||||||
|
|
||||||
HashMap<Character, ArrayList<Point>> allMapTiles = new HashMap<Character, ArrayList<Point>>();
|
HashMap<Character, ArrayList<Point>> allMapTiles = new HashMap<Character, ArrayList<Point>>();
|
||||||
@@ -36,6 +39,7 @@ public class MapEngine {
|
|||||||
}
|
}
|
||||||
this.createTiles(input);
|
this.createTiles(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapEngine() {
|
public MapEngine() {
|
||||||
Scanner input = null;
|
Scanner input = null;
|
||||||
try {
|
try {
|
||||||
@@ -49,6 +53,7 @@ public class MapEngine {
|
|||||||
}
|
}
|
||||||
this.createTiles(input);
|
this.createTiles(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTiles(Scanner input) {
|
private void createTiles(Scanner input) {
|
||||||
int lineCount = 0;
|
int lineCount = 0;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@@ -120,9 +125,6 @@ public class MapEngine {
|
|||||||
} else {
|
} else {
|
||||||
allMapTiles.get(currentLine.charAt(i)).add(new Point(x,y));
|
allMapTiles.get(currentLine.charAt(i)).add(new Point(x,y));
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* setze x und y auf die koordinaten für das objekt im NÄCHSTEN durchlauf
|
|
||||||
*/
|
|
||||||
if (x+singleTileWidth >= gamePanelWidth) {
|
if (x+singleTileWidth >= gamePanelWidth) {
|
||||||
x = 0;
|
x = 0;
|
||||||
y += singleTileWidth;
|
y += singleTileWidth;
|
||||||
@@ -133,68 +135,51 @@ public class MapEngine {
|
|||||||
lineCount++;
|
lineCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* wird wahrscheinlich anders umgesetzt. methode ist für testzwecke enthalten.
|
|
||||||
*/
|
|
||||||
// protected void addAllGameTilesToGamePanel(JPanel gamePanel) throws IOException {
|
|
||||||
// int x = 0;
|
|
||||||
// int y = 0;
|
|
||||||
// for (int i = 0; i<mapHeight; i++) {
|
|
||||||
// for (int j = 0; j < mapWidth; j++) {
|
|
||||||
// Objekt newGameTile = new Objekt(getTiles()[i][j]);
|
|
||||||
// newGameTile.setPosition(x, y);
|
|
||||||
// if (x+25 >= 800) {
|
|
||||||
// x = 0;
|
|
||||||
// y += 25;
|
|
||||||
// } else {
|
|
||||||
// x += 25;
|
|
||||||
// }
|
|
||||||
// gamePanel.add(newGameTile.getLabel());
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// gamePanel.repaint();
|
|
||||||
// }
|
|
||||||
// /*
|
|
||||||
// * get all tiles in a 2 dimensional char array
|
|
||||||
// */
|
|
||||||
// private char[][] getTiles() {
|
|
||||||
// return tiles;
|
|
||||||
// }
|
|
||||||
private HashMap<Character, ArrayList<Point>> getAllMapTiles() {
|
private HashMap<Character, ArrayList<Point>> getAllMapTiles() {
|
||||||
return allMapTiles;
|
return allMapTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<Character> getAvailableHardwareTileTypes() {
|
protected ArrayList<Character> getAvailableHardwareTileTypes() {
|
||||||
return availableHardwareTileTypes;
|
return availableHardwareTileTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<Point> getAllCoordinatesOfTileType(char c) {
|
protected ArrayList<Point> getAllCoordinatesOfTileType(char c) {
|
||||||
return getAllMapTiles().get(c);
|
return getAllMapTiles().get(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Point getFirstTilesCoordinatesOfTileType(char c) {
|
protected Point getFirstTilesCoordinatesOfTileType(char c) {
|
||||||
return getAllMapTiles().get(c).get(0);
|
return getAllMapTiles().get(c).get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Point getLastTilesCoordinatesOfTileType(char c) {
|
protected Point getLastTilesCoordinatesOfTileType(char c) {
|
||||||
return getAllMapTiles().get(c).get(getAllMapTiles().get(c).size()-1);
|
return getAllMapTiles().get(c).get(getAllMapTiles().get(c).size()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<StaticObject> getAllMapObjects() {
|
public ArrayList<StaticObject> getAllMapObjects() {
|
||||||
return MapObjectHandler.getAllMapObjects(this);
|
return MapObjectHandler.getAllMapObjects(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<StaticObject> getAllHardwareObjects() {
|
public ArrayList<StaticObject> getAllHardwareObjects() {
|
||||||
return MapObjectHandler.getAllHardwareObjects();
|
return MapObjectHandler.getAllHardwareObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<StaticObject> getAllWallObjects() {
|
public ArrayList<StaticObject> getAllWallObjects() {
|
||||||
return MapObjectHandler.getAllWallObjects();
|
return MapObjectHandler.getAllWallObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<StaticObject> getAllWayObjects() {
|
public ArrayList<StaticObject> getAllWayObjects() {
|
||||||
return MapObjectHandler.getAllWayObjects();
|
return MapObjectHandler.getAllWayObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<StaticObject> getAllHardwareTriggerObjects() {
|
public ArrayList<StaticObject> getAllHardwareTriggerObjects() {
|
||||||
return MapObjectHandler.getAllHardwareTriggerObjects();
|
return MapObjectHandler.getAllHardwareTriggerObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkIfPath(char c) {
|
private boolean checkIfPath(char c) {
|
||||||
return (c=='#');
|
return (c=='#');
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkIfHardware(char c) {
|
private boolean checkIfHardware(char c) {
|
||||||
for (char j = '0'; j <= '9'; j++) {
|
for (char j = '0'; j <= '9'; j++) {
|
||||||
if (j==c) {
|
if (j==c) {
|
||||||
@@ -203,6 +188,7 @@ public class MapEngine {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printMapGridWithTriggers() {
|
public void printMapGridWithTriggers() {
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < 24; i++) {
|
||||||
for (int j = 0; j < 32; j++) {
|
for (int j = 0; j < 32; j++) {
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package de.heatup.mapengine;
|
|||||||
import de.heatup.cfg.Config;
|
import de.heatup.cfg.Config;
|
||||||
|
|
||||||
public class MapGrid {
|
public class MapGrid {
|
||||||
|
|
||||||
private static MapGridCell[][] allGridCells = new MapGridCell[Config.mapMaxTilesWidth][Config.mapMaxTilesHeight];
|
private static MapGridCell[][] allGridCells = new MapGridCell[Config.mapMaxTilesWidth][Config.mapMaxTilesHeight];
|
||||||
|
|
||||||
private static MapGridCell dummyCell = new MapGridCell(); // 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)) {
|
||||||
MapGridCell newCell = new MapGridCell();
|
MapGridCell newCell = new MapGridCell();
|
||||||
@@ -12,6 +15,7 @@ public class MapGrid {
|
|||||||
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)) {
|
||||||
MapGridCell newCell = new MapGridCell();
|
MapGridCell newCell = new MapGridCell();
|
||||||
@@ -21,6 +25,7 @@ public class MapGrid {
|
|||||||
allGridCells[x][y] = newCell;
|
allGridCells[x][y] = newCell;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
MapGridCell newCell = new MapGridCell();
|
MapGridCell newCell = new MapGridCell();
|
||||||
@@ -29,6 +34,7 @@ public class MapGrid {
|
|||||||
allGridCells[x][y] = newCell;
|
allGridCells[x][y] = newCell;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MapGridCell getGridCell(int x, int y) {
|
public static MapGridCell getGridCell(int x, int y) {
|
||||||
if (!(x < 0 || x > Config.mapMaxTilesWidth-1 || y < 0 || y > Config.mapMaxTilesHeight-1)) {
|
if (!(x < 0 || x > Config.mapMaxTilesWidth-1 || y < 0 || y > Config.mapMaxTilesHeight-1)) {
|
||||||
return allGridCells[x][y];
|
return allGridCells[x][y];
|
||||||
|
|||||||
@@ -1,24 +1,33 @@
|
|||||||
package de.heatup.mapengine;
|
package de.heatup.mapengine;
|
||||||
|
|
||||||
public class MapGridCell {
|
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;
|
||||||
|
|
||||||
public char getCorrespondingHardwareToTrigger() {
|
public char getCorrespondingHardwareToTrigger() {
|
||||||
return correspondingHardwareToTrigger;
|
return correspondingHardwareToTrigger;
|
||||||
}
|
}
|
||||||
public void setCorrespondingHardwareToTrigger(char correspondingHardwareToTrigger) {
|
|
||||||
|
protected void setCorrespondingHardwareToTrigger(char correspondingHardwareToTrigger) {
|
||||||
this.correspondingHardwareToTrigger = correspondingHardwareToTrigger;
|
this.correspondingHardwareToTrigger = correspondingHardwareToTrigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPath() {
|
public boolean isPath() {
|
||||||
return isPath;
|
return isPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setPath(boolean isPath) {
|
protected void setPath(boolean isPath) {
|
||||||
this.isPath = isPath;
|
this.isPath = isPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTrigger() {
|
public boolean isTrigger() {
|
||||||
return isTrigger;
|
return isTrigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setTrigger(boolean isTrigger) {
|
protected void setTrigger(boolean isTrigger) {
|
||||||
this.isTrigger = isTrigger;
|
this.isTrigger = isTrigger;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user