mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 09:59:45 +02:00
Map Engine auf ClassLoader geaendert.
This commit is contained in:
@@ -11,6 +11,7 @@ import java.util.Scanner;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import de.heatup.cfg.Config;
|
import de.heatup.cfg.Config;
|
||||||
|
import de.heatup.highscore.HighscoreHandler;
|
||||||
import de.heatup.logging.Logger;
|
import de.heatup.logging.Logger;
|
||||||
import de.heatup.objects.*;
|
import de.heatup.objects.*;
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +32,10 @@ public class MapEngine {
|
|||||||
|
|
||||||
private final int gamePanelWidth = Config.gamePanelWidth;
|
private final int gamePanelWidth = Config.gamePanelWidth;
|
||||||
|
|
||||||
|
private static String mapString = "";
|
||||||
|
|
||||||
|
private final HighscoreHandler mapHighscore;
|
||||||
|
|
||||||
HashMap<Character, ArrayList<Point>> allMapTiles = new HashMap<Character, ArrayList<Point>>();
|
HashMap<Character, ArrayList<Point>> allMapTiles = new HashMap<Character, ArrayList<Point>>();
|
||||||
ArrayList<Character> availableHardwareTileTypes = new ArrayList<Character>();
|
ArrayList<Character> availableHardwareTileTypes = new ArrayList<Character>();
|
||||||
/**
|
/**
|
||||||
@@ -39,28 +44,26 @@ public class MapEngine {
|
|||||||
*/
|
*/
|
||||||
public MapEngine(int mapNumber) {
|
public MapEngine(int mapNumber) {
|
||||||
Scanner input = null;
|
Scanner input = null;
|
||||||
try {
|
MapLoader ml = new MapLoader();
|
||||||
input = new Scanner(MapLoader.loadMap(mapNumber));
|
input = new Scanner(ml.loadMap(mapNumber));
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
Logger.write("Could not find map file");
|
|
||||||
System.exit(-1);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.createTiles(input);
|
this.createTiles(input);
|
||||||
|
mapHighscore = new HighscoreHandler(mapString);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Öffnet einen File Chooser um eine Custom Map auszuwählen, welche anschließend geladen wird.
|
* Öffnet einen File Chooser um eine Custom Map auszuwählen, welche anschließend geladen wird.
|
||||||
*/
|
*/
|
||||||
public MapEngine() {
|
public MapEngine() {
|
||||||
Scanner input = null;
|
Scanner input = null;
|
||||||
|
MapLoader ml = new MapLoader();
|
||||||
try {
|
try {
|
||||||
input = new Scanner(MapLoader.chooseMap());
|
input = new Scanner(ml.chooseMap());
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Logger.write("Map file not found");
|
Logger.write("Map file not found");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
this.createTiles(input);
|
this.createTiles(input);
|
||||||
|
mapHighscore = new HighscoreHandler(mapString);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Erstellt aus einem gegebenen Scanner, welche eine Datei einliest,
|
* Erstellt aus einem gegebenen Scanner, welche eine Datei einliest,
|
||||||
@@ -73,6 +76,7 @@ public class MapEngine {
|
|||||||
int y = 0;
|
int y = 0;
|
||||||
while (input.hasNextLine() && lineCount <= mapHeight) {
|
while (input.hasNextLine() && lineCount <= mapHeight) {
|
||||||
String currentLine = input.nextLine();
|
String currentLine = input.nextLine();
|
||||||
|
mapString = mapString+currentLine;
|
||||||
for (int i = 0; i<mapWidth; i++) {
|
for (int i = 0; i<mapWidth; i++) {
|
||||||
/* MapGrid implementation */
|
/* MapGrid implementation */
|
||||||
if (checkIfPath(currentLine.charAt(i))) {
|
if (checkIfPath(currentLine.charAt(i))) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.heatup.mapengine;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
|
|
||||||
@@ -9,10 +10,11 @@ import de.heatup.cfg.Config;
|
|||||||
import de.heatup.logging.Logger;
|
import de.heatup.logging.Logger;
|
||||||
|
|
||||||
public class MapLoader {
|
public class MapLoader {
|
||||||
protected static File chooseMap() {
|
protected File chooseMap() {
|
||||||
JFileChooser chooser = new JFileChooser();
|
JFileChooser chooser = new JFileChooser();
|
||||||
chooser.showOpenDialog(null);
|
chooser.showOpenDialog(null);
|
||||||
File mapFile = null;
|
File mapFile = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Config.mapFilePath = chooser.getSelectedFile().getCanonicalPath().toString();
|
Config.mapFilePath = chooser.getSelectedFile().getCanonicalPath().toString();
|
||||||
mapFile = chooser.getSelectedFile();
|
mapFile = chooser.getSelectedFile();
|
||||||
@@ -23,13 +25,10 @@ public class MapLoader {
|
|||||||
}
|
}
|
||||||
return mapFile;
|
return mapFile;
|
||||||
}
|
}
|
||||||
protected static File loadMap(int mapNumber) {
|
protected InputStream loadMap(int mapNumber) {
|
||||||
File mapFile = null;
|
ClassLoader cl = this.getClass().getClassLoader();
|
||||||
|
InputStream is = cl.getResourceAsStream("de/heatup/resources/maps/map"+mapNumber+".txt");
|
||||||
String mapPath = "src/de/heatup/resources/maps/map"+mapNumber+".txt";
|
Logger.write("Map de/heatup/resources/maps/map"+mapNumber+".txt loaded");
|
||||||
|
return is;
|
||||||
mapFile = new File(mapPath);
|
|
||||||
Logger.write("Map \""+ mapPath + "\" loaded");
|
|
||||||
return mapFile;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user