Hallo 🙂
Diesmal habe ich das Problem, dass immer "0" ausgegeben wird. Nur wieso?
Wenn ich die map.properties manuell mit z.B. dem Editor öffne, sieht alles richtig aus, und die Werte sind richtig gespeichert.
Das nicht korrekte Problem sieht so aus:
Diesmal habe ich das Problem, dass immer "0" ausgegeben wird. Nur wieso?
Wenn ich die map.properties manuell mit z.B. dem Editor öffne, sieht alles richtig aus, und die Werte sind richtig gespeichert.
Code:
0,0=Strasse
0,1=Baum
0,2=0
0,3=0
0,4=Haus
usw...
Java:
import java.awt.Dimension;
import java.awt.Graphics;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Game extends JPanel {
private static final long serialVersionUID = 1L;
JFrame frame = new JFrame();
Properties prop = new Properties();
public static void main(String[] args) {
new Game();
}
public Game() {
this.setPreferredSize(new Dimension(400, 400));
this.setLayout(null);
frame = new JFrame("2D Spiel");
frame.setLocation(100, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(this);
frame.pack();
frame.setVisible(true);
repaint();
}
public void paint(Graphics g)
{
super.paint(g);
try {
prop.load(new FileInputStream("map.properties"));
for (int x = 0; x < 20; x++) {
for (int y = 0; y < 20; y++) {
g.drawString(prop.getProperty(x + "," + y), GetCoord(x), GetCoord(y));
}
}
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
Das nicht korrekte Problem sieht so aus: