mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 10:19:46 +02:00
Neue Methoden hinzugefügt.
MapEngine erzeugt nun effektiv eine Map mit einer Koordinatenliste für jeden Tile Typ. Dieser kann flexibler eingesetzt werden. Zum Beispiel kann so einfach bestimmt werden, wie groß manipulierbare Tiles in ihrer Gesamtfläche sind und außerdem können wir sowohl Graphics als auch JLabel zum Zeichnen nehmen.
This commit is contained in:
@@ -10,6 +10,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import de.heatup.logging.Logger;
|
||||
@@ -19,7 +20,11 @@ public class MapEngine {
|
||||
final int mapHeight = 24;
|
||||
final int mapWidth = 32;
|
||||
HashMap<Character, ArrayList<Point>> allMapTiles = new HashMap<Character, ArrayList<Point>>();
|
||||
ArrayList<Character> availableTileTypes = new ArrayList<Character>();
|
||||
char[][] tiles;
|
||||
/*
|
||||
* öffnet die map mit der gegebenen nummer aus den resourcen.
|
||||
*/
|
||||
MapEngine(int mapNumber) {
|
||||
tiles = new char[mapHeight][mapWidth];
|
||||
Scanner input = null;
|
||||
@@ -32,6 +37,23 @@ public class MapEngine {
|
||||
}
|
||||
this.createTiles(input);
|
||||
}
|
||||
/*
|
||||
* öffnet einen file chooser um eine benutzer erstellte map zu öffnen
|
||||
*/
|
||||
MapEngine() {
|
||||
tiles = new char[mapHeight][mapWidth];
|
||||
Scanner input = null;
|
||||
try {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.showOpenDialog(null);
|
||||
input = new Scanner(chooser.getSelectedFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
Logger.write("Konnte Map Datei nicht finden");
|
||||
System.exit(-1);
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.createTiles(input);
|
||||
}
|
||||
private void createTiles(Scanner input) {
|
||||
int lineCount = 0;
|
||||
int x = 0;
|
||||
@@ -48,6 +70,7 @@ public class MapEngine {
|
||||
ArrayList<Point> newTileType = new ArrayList<Point>();
|
||||
newTileType.add(new Point(x,y));
|
||||
allMapTiles.put(currentLine.charAt(i), newTileType);
|
||||
availableTileTypes.add(currentLine.charAt(i));
|
||||
} else {
|
||||
allMapTiles.get(currentLine.charAt(i)).add(new Point(x,y));
|
||||
}
|
||||
@@ -64,6 +87,9 @@ public class MapEngine {
|
||||
lineCount++;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* wird wahrscheinlich anders umgesetzt. methode ist für testzwecke enthalten.
|
||||
*/
|
||||
public void addAllGameTilesToGamePanel(JPanel gamePanel) throws IOException {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
@@ -78,23 +104,25 @@ public class MapEngine {
|
||||
x += 25;
|
||||
}
|
||||
gamePanel.add(newGameTile.getLabel());
|
||||
/*
|
||||
* natürlich performanter, wenn es außerhalb der schleifen steht, aber so
|
||||
* sieht es cooler aus :)
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
gamePanel.repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* get all tiles in a 2 dimensional char array
|
||||
*/
|
||||
private char[][] getTiles() {
|
||||
return tiles;
|
||||
}
|
||||
public HashMap<Character, ArrayList<Point>> getAllMapTiles() {
|
||||
private HashMap<Character, ArrayList<Point>> getAllMapTiles() {
|
||||
return allMapTiles;
|
||||
}
|
||||
public ArrayList<Character> getAvailableTileTypes() {
|
||||
return availableTileTypes;
|
||||
}
|
||||
public ArrayList<Point> getCoordinatesOfTileType(char c) {
|
||||
return getAllMapTiles().get(c);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user