Beh ci ho provato ma non cambia nulla.
Questo è il JPanel che mostra il labirinto:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MazePanel extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
private final int DIM = 41;
private Timer timer;
private Maze m;
private Player p;
public MazePanel() {
m = new Maze(DIM);
p = new Player();
setPreferredSize(new Dimension(DIM*15,DIM*15));
addKeyListener(new Al());
setFocusable(true);
timer = new Timer(25, this);
timer.start();
}
@Override
public void actionPerformed(ActionEvent event) {
if(m.getMap(p.getTileX(), p.getTileY())==2) {
JOptionPane.showMessageDialog(null,"HAI VINTO!");
System.exit(0);
}
repaint();
}
public void paint(Graphics g) {
super.paint(g);
for (int y = 0; y < DIM; y++) {
for (int x = 0; x < DIM; x++) {
if (m.getMap(x, y) == 0) {
g.drawImage(m.getGrass(), x * 15, y * 15, null);
}
if (m.getMap(x, y) == 1) {
g.drawImage(m.getWall(), x * 15, y * 15, null);
}
if (m.getMap(x, y) == 2) {
g.drawImage(m.getFinish(), x * 15, y * 15, null);
}
}
}
g.drawImage(p.getPlayer(), p.getTileX() * 15, p.getTileY() * 15, null);
}
class Al extends KeyAdapter {
public void keyPressed(KeyEvent e) {
int keycode = e.getKeyCode();
if(keycode == KeyEvent.VK_W) {
if(m.getMap(p.getTileX(), p.getTileY()-1) != 1) {
p.move(0, -1);
}
}
if(keycode == KeyEvent.VK_S) {
if(m.getMap(p.getTileX(), p.getTileY()+1) != 1) {
p.move(0, 1);
}
}
if(keycode == KeyEvent.VK_A) {
if(m.getMap(p.getTileX()-1, p.getTileY()) != 1) {
p.move(-1, 0);
}
}
if(keycode == KeyEvent.VK_D) {
if(m.getMap(p.getTileX()+1, p.getTileY()) != 1) {
p.move(1, 0);
}
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
}
public void reset() {
}
}