Ahi va la clase que faltaba.
Código Java:
Ver originalpackage ciudad;
private Interfaz LaberintoVirtual = new Interfaz();
initComponents();
GenerarLaberintoGrafico();
// hilo = new Thread(this);
}
private void GenerarLaberintoGrafico() {
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
LaberintoGrafico
[i
][j
] = new JPanel();
add(LaberintoGrafico[i][j]);
}
}
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
LaberintoGrafico[i][j].setBounds(i * LaberintoVirtual.DevolverLargoImagenes(), j * LaberintoVirtual.DevolverAlturaImagenes(), LaberintoVirtual.DevolverLargoImagenes(), LaberintoVirtual.DevolverAlturaImagenes());
LaberintoGrafico[i][j].validate();
}
}
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
String a
= LaberintoVirtual.
DeolverCodigoImagenMatriz(i, j
);
if (a == "x") {
LaberintoGrafico
[i
][j
].
setBackground(Color.
GREEN); }
if (a == "e" || a == "up" || a == "left" || a == "rigth" || a == "down") {
LaberintoGrafico
[i
][j
].
setBackground(Color.
GRAY); }
}
}
}
public void inicio() {
x = 0;
y = 60;
dx = 15;
dy = 0;
new Auto().start();
}
public void pausa() {
hilo.suspend();
}
public void reanudar() {
hilo.resume();
}
int x = 0;
int y = 60;
int f;
int d;
int dx = 15;
int dy = 0;
int ban = 1;
@Override
super.paint(g);
Image imagen
= t.
getImage("auto.gif");
g.drawImage(imagen, x, y, 15, 15, this);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addGap(0,
400,
Short.
MAX_VALUE) );
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addGap(0,
300,
Short.
MAX_VALUE) );
}// </editor-fold>
// Variables declaration - do not modify
// End of variables declaration
@Override
public void run() {
}
public class Auto
extends Thread {
public Auto() {
this.imagen = t.getImage("auto.gif");
}
@Override
public void run() {
System.
out.
println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); try {
//while(true){
System.
out.
println("ooooooooooooooooooooooooooooooooooo"); System.
out.
println(x
+ "wwwwwwwwwwwwwwww" + y
+ "qqqqqqqq" + getHeight
() + "rrrrrrrrrr" + getWidth
()); while (x < getWidth() - 20 && y < getHeight() - 20 && y > -16) {
System.
out.
println(x
+ "dddddddddddddddddddddddddddddddddd" + y
);
x += dx;
int incrementoX = dx;
y += dy;
int incrementoY = dy;
repaint();
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
if (x == LaberintoGrafico[i][j].getX()) {
f = i;
}
if (y == LaberintoGrafico[i][j].getY()) {
d = j;
}
}
}
int sent = LaberintoVirtual.DevolverSentido(f, d);
int random
= (int) (Math.
random() * 100 + 1); if (sent == 5 && random % 2 == 0) {
System.
out.
println(random
+ "kkkkkkkkkkkkkkkkkk"); //ban=1;
if (incrementoY > 0) {
if (LaberintoVirtual.DevolverSentido(f, d - 1) == 3 && LaberintoVirtual.DevolverSentido(f - 1, d) == 1) {
dx = 15;
dy = 0;
System.
out.
println("Bajando y dobla a derecha "); }
if (LaberintoVirtual.DevolverSentido(f, d - 1) == 3 && LaberintoVirtual.DevolverSentido(f - 1, d) == 2) {
dx = -15;
dy = 0;
System.
out.
println("Bajando y dobla a izqierda "); }
}
if (incrementoX > 0) {
if (LaberintoVirtual.DevolverSentido(f - 1, d) == 1 && LaberintoVirtual.DevolverSentido(f, d - 1) == 4) {
dx = 0;
dy = -15;
System.
out.
println("Va por derecha y dobla arriba"); }
if (LaberintoVirtual.DevolverSentido(f - 1, d) == 1 && LaberintoVirtual.DevolverSentido(f, d - 1) == 3) {
dx = 0;
dy = 15;
System.
out.
println("Va por derecha y dobla abajo"); }
}
if (incrementoX < 0) {
if (LaberintoVirtual.DevolverSentido(f + 1, d) == 2 && LaberintoVirtual.DevolverSentido(f, d - 1) == 3) {
dx = 0;
dy = 15;
System.
out.
println("Va por izquierda y dobla abajo"); }
if (LaberintoVirtual.DevolverSentido(f + 1, d) == 2 && LaberintoVirtual.DevolverSentido(f, d - 1) == 4) {
dx = 0;
dy = -15;
System.
out.
println("Va por izquierda y dobla arriba"); }
}
if (incrementoY < 0) {
if (LaberintoVirtual.DevolverSentido(f, d + 1) == 4 && LaberintoVirtual.DevolverSentido(f - 1, d) == 1) {
dx = 15;
dy = 0;
System.
out.
println("Va subiendo y dobla a derecha"); }
if (LaberintoVirtual.DevolverSentido(f, d + 1) == 4 && LaberintoVirtual.DevolverSentido(f, d - 1) == 2) {
dx = -15;
dy = 0;
System.
out.
println("Va subiendo y dobla a izquierda"); }
}
}
}
System.
out.
println("sucedio un error" + e.
getMessage()); }
}
}
}
Espero su colaboracion. Gracias.