mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:39:45 +02:00
Statische Logger-Klasse hinzugefügt. Bitte Kommentare in der Klasse
beachten. Sollte aber selbsterklärend sein. Könnte praktisch sein, wenn man Debug Sysos im Code mit einem Aufruf deaktivieren möchte. Änderungen in der MapEngine wegen Anpassung der Objekt-Klasse.
This commit is contained in:
@@ -0,0 +1,92 @@
|
|||||||
|
package de.heatup.logging;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
public class Logger {
|
||||||
|
private static boolean logging = false;
|
||||||
|
private static boolean firstWrite = true;
|
||||||
|
private static boolean toCmd = true;
|
||||||
|
private static boolean toFile = false;
|
||||||
|
private static String logFile;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* writes a new log line to cmd via System.out.println() and/or (if enabled) appends a new line to a log file
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
public static void write(String s) {
|
||||||
|
if (logging) {
|
||||||
|
if (toCmd) {
|
||||||
|
System.out.println(s);
|
||||||
|
}
|
||||||
|
if (toFile) {
|
||||||
|
PrintStream out;
|
||||||
|
try {
|
||||||
|
if (firstWrite) {
|
||||||
|
out = new PrintStream(new FileOutputStream(logFile));
|
||||||
|
firstWrite = false;
|
||||||
|
} else {
|
||||||
|
out = new PrintStream(new FileOutputStream(logFile, true));
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
File f = new File(logFile);
|
||||||
|
try {
|
||||||
|
f.createNewFile();
|
||||||
|
if (firstWrite) {
|
||||||
|
out = new PrintStream(new FileOutputStream(logFile));
|
||||||
|
firstWrite = false;
|
||||||
|
} else {
|
||||||
|
out = new PrintStream(new FileOutputStream(logFile, true));
|
||||||
|
}
|
||||||
|
} catch (IOException e1) {
|
||||||
|
out = null;
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.println(s);
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* sets the log file to given logFile.
|
||||||
|
* logFile can include a path.
|
||||||
|
*/
|
||||||
|
public static void setLogFile(String logFile) {
|
||||||
|
Logger.toFile = true;
|
||||||
|
Logger.logFile = logFile;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* prints the name (and path if given)
|
||||||
|
*/
|
||||||
|
public static String getLogFile() {
|
||||||
|
return Logger.logFile;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* enables logging
|
||||||
|
* logging is enabled by default
|
||||||
|
*/
|
||||||
|
public static void enableLogging() {
|
||||||
|
Logger.logging = true;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* disables logging until reenabled with enableLogging()
|
||||||
|
*/
|
||||||
|
public static void disableLogging() {
|
||||||
|
Logger.logging = false;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* disables System.out.println() logging
|
||||||
|
*/
|
||||||
|
public static void disableCmdLogging() {
|
||||||
|
Logger.toCmd = false;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* enables System.out.println() logging
|
||||||
|
*/
|
||||||
|
public static void enableCmdLogging() {
|
||||||
|
Logger.toCmd = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,36 +1,23 @@
|
|||||||
|
package de.heatup.mapengine;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Stack;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import de.heatup.objects.*;
|
import de.heatup.objects.*;
|
||||||
|
|
||||||
public class MapEngine {
|
public class MapEngine {
|
||||||
int[][] tiles;
|
char[][] tiles;
|
||||||
Stack<Integer> tileID;
|
|
||||||
Map<Integer, ArrayList<Objekt>> tilesMap;
|
|
||||||
MapEngine() {
|
MapEngine() {
|
||||||
tiles = new int[24][32];
|
tiles = new char[24][32];
|
||||||
tileID = new Stack<Integer>();
|
|
||||||
tilesMap = new HashMap<Integer, ArrayList<Objekt>>();
|
|
||||||
ArrayList<Objekt> typeArrayListOne = new ArrayList<Objekt>();
|
|
||||||
ArrayList<Objekt> typeArrayListTwo = new ArrayList<Objekt>();
|
|
||||||
ArrayList<Objekt> typeArrayListThree = new ArrayList<Objekt>();
|
|
||||||
tilesMap.put(1, typeArrayListOne);
|
|
||||||
tilesMap.put(2, typeArrayListTwo);
|
|
||||||
tilesMap.put(3, typeArrayListThree);
|
|
||||||
Scanner input = null;
|
Scanner input = null;
|
||||||
try {
|
try {
|
||||||
input = new Scanner(new File("prp/spielfeld.txt"));
|
input = new Scanner(new File("src/de/heatup/resources/maps/map1.txt"));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("Konnte Map Datei nicht finden");
|
System.out.println("Konnte Map Datei nicht finden");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
@@ -43,36 +30,35 @@ public class MapEngine {
|
|||||||
while (input.hasNextLine()) {
|
while (input.hasNextLine()) {
|
||||||
String currentLine = input.nextLine();
|
String currentLine = input.nextLine();
|
||||||
for (int i = 0; i<32; i++) {
|
for (int i = 0; i<32; i++) {
|
||||||
tiles[lineCount][i] = defineTileType(currentLine.charAt(i));
|
// tiles[lineCount][i] = defineTileType(currentLine.charAt(i));
|
||||||
|
tiles[lineCount][i] = currentLine.charAt(i);
|
||||||
}
|
}
|
||||||
lineCount++;
|
lineCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private int defineTileType(char charAt) {
|
// private int defineTileType(char charAt) {
|
||||||
for (char i = '0'; i<'9';i++) {
|
// for (char i = '0'; i<'9';i++) {
|
||||||
if (charAt == i) {
|
// if (charAt == i) {
|
||||||
tileID.push(i-'0');
|
// tileID.push(i-'0');
|
||||||
return 2;
|
// return 2;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
switch (charAt) {
|
// switch (charAt) {
|
||||||
case '#':
|
// case '#':
|
||||||
return 1;
|
// return 1;
|
||||||
case '-':
|
// case '-':
|
||||||
return 3;
|
// return 3;
|
||||||
default:
|
// default:
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
public void addAllGameTilesToPanel(JPanel gamePanel) throws IOException {
|
public void addAllGameTilesToPanel(JPanel gamePanel) throws IOException {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
gamePanel.setBackground(new Color(500)); // hintergrund gamepanel auf blau setzen, bitte entfernen, ist unnötig
|
gamePanel.setBackground(new Color(500)); // hintergrund gamepanel auf blau setzen, bitte entfernen, ist unnötig
|
||||||
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++) {
|
||||||
Objekt newGameTile = new Objekt(""); // ändern!!!!! nicht mit parameter "" aufrufen!!!
|
Objekt newGameTile = new Objekt(tiles[i][j]);
|
||||||
System.out.println(tiles[i][j]);
|
|
||||||
newGameTile.setObjectType(tiles[i][j]);
|
|
||||||
newGameTile.setPosition(x, y);
|
newGameTile.setPosition(x, y);
|
||||||
if (x+25 >= 800) {
|
if (x+25 >= 800) {
|
||||||
x = 0;
|
x = 0;
|
||||||
@@ -81,14 +67,10 @@ public class MapEngine {
|
|||||||
x += 25;
|
x += 25;
|
||||||
}
|
}
|
||||||
gamePanel.add(newGameTile.getLabel());
|
gamePanel.add(newGameTile.getLabel());
|
||||||
tilesMap.get(tiles[i][j]).add(newGameTile);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
gamePanel.repaint();
|
gamePanel.repaint();
|
||||||
}
|
}
|
||||||
public ArrayList<Objekt> getAllTilesOfType(int i) {
|
|
||||||
return tilesMap.get(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user