mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 10:09:44 +02:00
Merge branch 'master' of github.com:jokerx3/prp
This commit is contained in:
@@ -10,6 +10,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import de.heatup.logging.Logger;
|
import de.heatup.logging.Logger;
|
||||||
@@ -19,7 +20,11 @@ public class MapEngine {
|
|||||||
final int mapHeight = 24;
|
final int mapHeight = 24;
|
||||||
final int mapWidth = 32;
|
final int mapWidth = 32;
|
||||||
HashMap<Character, ArrayList<Point>> allMapTiles = new HashMap<Character, ArrayList<Point>>();
|
HashMap<Character, ArrayList<Point>> allMapTiles = new HashMap<Character, ArrayList<Point>>();
|
||||||
|
ArrayList<Character> availableTileTypes = new ArrayList<Character>();
|
||||||
char[][] tiles;
|
char[][] tiles;
|
||||||
|
/*
|
||||||
|
* öffnet die map mit der gegebenen nummer aus den resourcen.
|
||||||
|
*/
|
||||||
MapEngine(int mapNumber) {
|
MapEngine(int mapNumber) {
|
||||||
tiles = new char[mapHeight][mapWidth];
|
tiles = new char[mapHeight][mapWidth];
|
||||||
Scanner input = null;
|
Scanner input = null;
|
||||||
@@ -32,6 +37,23 @@ public class MapEngine {
|
|||||||
}
|
}
|
||||||
this.createTiles(input);
|
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) {
|
private void createTiles(Scanner input) {
|
||||||
int lineCount = 0;
|
int lineCount = 0;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@@ -48,6 +70,7 @@ public class MapEngine {
|
|||||||
ArrayList<Point> newTileType = new ArrayList<Point>();
|
ArrayList<Point> newTileType = new ArrayList<Point>();
|
||||||
newTileType.add(new Point(x,y));
|
newTileType.add(new Point(x,y));
|
||||||
allMapTiles.put(currentLine.charAt(i), newTileType);
|
allMapTiles.put(currentLine.charAt(i), newTileType);
|
||||||
|
availableTileTypes.add(currentLine.charAt(i));
|
||||||
} else {
|
} else {
|
||||||
allMapTiles.get(currentLine.charAt(i)).add(new Point(x,y));
|
allMapTiles.get(currentLine.charAt(i)).add(new Point(x,y));
|
||||||
}
|
}
|
||||||
@@ -64,6 +87,9 @@ public class MapEngine {
|
|||||||
lineCount++;
|
lineCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* wird wahrscheinlich anders umgesetzt. methode ist für testzwecke enthalten.
|
||||||
|
*/
|
||||||
public void addAllGameTilesToGamePanel(JPanel gamePanel) throws IOException {
|
public void addAllGameTilesToGamePanel(JPanel gamePanel) throws IOException {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
@@ -78,15 +104,11 @@ public class MapEngine {
|
|||||||
x += 25;
|
x += 25;
|
||||||
}
|
}
|
||||||
gamePanel.add(newGameTile.getLabel());
|
gamePanel.add(newGameTile.getLabel());
|
||||||
/*
|
|
||||||
* natürlich performanter, wenn es außerhalb der schleifen steht, aber so
|
|
||||||
* sieht es cooler aus :)
|
|
||||||
*/
|
|
||||||
gamePanel.repaint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
gamePanel.repaint();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* get all tiles in a 2 dimensional char array
|
* get all tiles in a 2 dimensional char array
|
||||||
@@ -94,7 +116,13 @@ public class MapEngine {
|
|||||||
private char[][] getTiles() {
|
private char[][] getTiles() {
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
public HashMap<Character, ArrayList<Point>> getAllMapTiles() {
|
private HashMap<Character, ArrayList<Point>> getAllMapTiles() {
|
||||||
return allMapTiles;
|
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