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

This commit is contained in:
andreas
2014-11-01 09:36:11 +01:00
+37 -9
View File
@@ -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,23 +104,25 @@ 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
*/ */
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);
}
} }