How to debug an infinite loop

1

Hello, I am creating a game in POO (I can not use polymorphism, interfaces, inheritance, overwriting of methods, among others. It is generating an infinite loop and I do not know where the error comes from.

I have not set class 1 (main method) because I'm over the limit of words. If someone needs it in comments I'll put it.

Class 2:

    public static final int TIPO_VACIA = 1;
public static final int TIPO_LIMITE = 2;
public static final int TIPO_ITEM = 3;
public static final double TIPO_S = 4;
public static final double TIPO_Z = 5;
public static final double TIPO_SALIDA = 6;
public static final String tipoVaciaTexto = " ";
public static final String tipoLimiteTexto = "░░░" + "|" + "░░░";
public static final String tipoItemTexto = "░░░" + "x" + "░░░";
public static final String SIMBOLO_S = "░░░" + "S" + "░░░";
public static final String SIMBOLO_Z = "Z";
public static final String SALIDA = "░░░" + "░" + "░░░";


//atributos de casilla
 private double tipoCasilla;
 private Point locCasilla;

 //get y set

public double getTipoCasilla() {
    return tipoCasilla;
}

public void setTipoCasilla(double tipoCasilla) {
    this.tipoCasilla = tipoCasilla;
}

public Point getLocCasilla() {
    return locCasilla;
}

public void setLocCasilla(Point locCasilla) {
    this.locCasilla = locCasilla;
}


public Casilla(double tipoCasilla) {
    this.tipoCasilla = tipoCasilla;
}



public String toString() {
    String infoCasilla;
    if (this.tipoCasilla == 1) {
        infoCasilla = Casilla.tipoVaciaTexto;
    } else if (this.tipoCasilla == 2) {
        infoCasilla = Casilla.tipoLimiteTexto;
    } else if (this.tipoCasilla == 3) {
        infoCasilla = Casilla.tipoItemTexto;
    } else if (this.tipoCasilla == 4) {
        infoCasilla = Casilla.SIMBOLO_S;
    } else if (this.tipoCasilla == 5) {
        infoCasilla = Casilla.SIMBOLO_Z;
    } else {
        infoCasilla = Casilla.SALIDA;
    }

    return infoCasilla;
}

//comprobar que no haya una pared
public boolean hayLimite() {

    return this.tipoCasilla == TIPO_LIMITE;
}

//para saber si hay un objeto

public boolean hayItem() {

    return this.tipoCasilla == TIPO_ITEM;

}


//si hay un zombie 
public boolean contenidoParaZombie() {
    boolean HayObstaculo = false;
    if (this.getTipoCasilla() == TIPO_LIMITE) {
        HayObstaculo = true;
    } else if (getTipoCasilla() == TIPO_ITEM) {
        HayObstaculo = true;
    } else if (this.getTipoCasilla() == TIPO_Z) {
        HayObstaculo = true;
    } else if (this.getTipoCasilla() == TIPO_SALIDA) {
        HayObstaculo = true;
    }
    return HayObstaculo;
    }

    }

CLASS 3:

 //Atributos de partida
private Superviviente superviviente;
private Zombies[] zombies;
private int numeroZombiesPartida = 3;
private int vidasPartida = 3;
private int puntos = 0;
private int items = 0;
private char movimientoElegido = ' ';


private Tablero mapaEnPartida;

  //Constructor 
    public Partida(Tablero mapa) {
    mapaEnPartida = mapa;
    this.superviviente = new Superviviente(mapa);
    this.zombies = new Zombies[3];
    this.items = this.mapaEnPartida.getItemsTablero();

    for (int i = 0; i < numeroZombiesPartida; i++) {
        zombies[i] = new Zombies(mapa,     this.superviviente.getPosicionS());
    }
}

public Partida() {

}

//Gets y Sets


public char getMovimientoElegido() {
    return movimientoElegido;
}

public void setMovimientoElegido(char movimientoElegido) {
    this.movimientoElegido = movimientoElegido;
}

public Superviviente getSuperviviente() {
    return superviviente;
}

public void setSuperviviente(Superviviente superviviente) {
    this.superviviente = superviviente;
}

public Zombies[] getZombies() {
    return zombies;
}

public void setZombies(Zombies[] zombies) {
    this.zombies = zombies;
}

public int getVidasPartida() {
    return vidasPartida;
}

public void setVidasPartida(int vidasPartida) {
    this.vidasPartida = vidasPartida;
}

public int getPuntos() {
    return puntos;
}

public void setPuntos(int puntos) {
    this.puntos = puntos;
}

public int getItems() {
    return items;
}

public void setItems(int items) {
    this.items = items;
}

public Tablero getMapaEnPartida() {
    return mapaEnPartida;
}

public void setMapaEnPartida(Tablero mapaEnPartida) {
    this.mapaEnPartida = mapaEnPartida;
}

public int getNumeroZombiesPartida() {
    return numeroZombiesPartida;
}

public void setNumeroZombiesPartida(int numeroZombiesPartida) {
    this.numeroZombiesPartida = numeroZombiesPartida;
}

/**
 * Pide el movimiento por consola
 */




/**
 * Mueve al superviviente en la partida, mirando si hay una pared o un item.
 */
public void moverseEnPartidaS() {
    int X = (int) this.superviviente.getPosicionS().getX();
    int Y = (int) this.superviviente.getPosicionS().getY();
    if (this.movimientoElegido == 'W') {
        if (mapaEnPartida.getMapaCasillasW(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_LIMITE) {
            System.out.println("Hay una pared");
        } else if (mapaEnPartida.getMapaCasillasW(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_SALIDA) {

            this.superviviente.getPosicionS().move(X, Y - 1);
            mapaEnPartida.getMapaCasillas(this.superviviente.getPosicionS()).setTipoCasilla(Casilla.TIPO_SALIDA);
        } else {

            mapaEnPartida.getMapaCasillas(this.superviviente.getPosicionS()).setTipoCasilla(Casilla.TIPO_VACIA);
            this.superviviente.getPosicionS().move(X, Y - 1);
            if (mapaEnPartida.getMapaCasillas(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_ITEM) {
                setPuntos(getPuntos() + 100);
                System.out.println("Has cogido un item!!");
                System.out.println("");
                setItems(getItems() - 1);

            }

        }

    } else if (this.movimientoElegido == 'S') {
        if (mapaEnPartida.getMapaCasillasS(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_LIMITE) {
            System.out.println("Hay una pared");
        } else if (mapaEnPartida.getMapaCasillasS(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_SALIDA) {
            this.superviviente.getPosicionS().move(X, Y - 1);
        } else {

            mapaEnPartida.getMapaCasillas(this.superviviente.getPosicionS()).setTipoCasilla(Casilla.TIPO_VACIA);
            this.superviviente.getPosicionS().move(X, Y + 1);
            if (mapaEnPartida.getMapaCasillas(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_ITEM) {
                setPuntos(getPuntos() + 100);
                System.out.println("Has cogido un item!!");
                System.out.println("");
                setItems(getItems() - 1);

            }

        }

    } else if (this.movimientoElegido == 'A') {
        if (mapaEnPartida.getMapaCasillasA(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_LIMITE) {
            System.out.println( "Hay una pared");
        } else if (mapaEnPartida.getMapaCasillasA(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_SALIDA) {
            this.superviviente.getPosicionS().move(X, Y - 1);
        } else {

            mapaEnPartida.getMapaCasillas(this.superviviente.getPosicionS()).setTipoCasilla(Casilla.TIPO_VACIA);
            this.superviviente.getPosicionS().move(X - 1, Y);
            if (mapaEnPartida.getMapaCasillas(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_ITEM) {
                setPuntos(getPuntos() + 100);
                System.out.println("Has cogido un item!!");
                System.out.println("");
                setItems(getItems() - 1);

            }

        }

    } else if (this.movimientoElegido == 'D') {
        if (mapaEnPartida.getMapaCasillasD(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_LIMITE) {
            System.out.println("Hay una pared");
        } else if (mapaEnPartida.getMapaCasillasD(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_SALIDA) {
            this.superviviente.getPosicionS().move(X, Y - 1);
        } else {

            mapaEnPartida.getMapaCasillas(this.superviviente.getPosicionS()).setTipoCasilla(Casilla.TIPO_VACIA);
            this.superviviente.getPosicionS().move(X + 1, Y);
            if (mapaEnPartida.getMapaCasillas(this.superviviente.getPosicionS()).getTipoCasilla() == Casilla.TIPO_ITEM) {
                setPuntos(getPuntos() + 100);
                System.out.println("Has cogido un item!!");
                System.out.println("");
                setItems(getItems() - 1);

            }


        }


    }
}

/**
 * Genera un movimiento aleatorio
 *
 * @return
 */
public int direccionRandom() {
    int direccion = (int) Math.round(Math.random() * 4);
    char direccionAleatoria = ' ';
    switch (direccion) {
        case 1:
            direccionAleatoria = 'W';
            break;
        case 2:
            direccionAleatoria = 'S';
            break;

        case 3:
            direccionAleatoria = 'A';
            break;

        case 4:
            direccionAleatoria = 'D';
            break;

    }
    return direccionAleatoria;
}

/**
 * Mueve a los objetos zombies creados en partida comprobando que puedan
 * moverse
 */
public void moverseEnPartidaZ() {
    int direccionAleatoria = direccionRandom();
    for (int i = 0; i < this.zombies.length; i++) {
        int intentos = 3;
        boolean posicionSeaValida = false;
        int X = (int) this.zombies[i].getPosicionZ().getX();
        int Y = (int) this.zombies[i].getPosicionZ().getY();
        while (intentos > 0 && !posicionSeaValida) {
            if (this.zombies[i].getPosicionZ().equals(this.superviviente.getPosicionS())) {
                break;
            }
            switch (direccionAleatoria) {
                case 'W':

                    if (!mapaEnPartida.getMapaCasillasCoord(X, Y - 1).contenidoParaZombie()) {
                        mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_VACIA);
                        this.zombies[i].getPosicionZ().move(X, Y - 1);
                        mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_Z);
                        posicionSeaValida = true;
                    }
                    break;
                case 'S':
                    if (!mapaEnPartida.getMapaCasillasCoord(X, Y + 1).contenidoParaZombie()) {
                        mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_VACIA);
                        this.zombies[i].getPosicionZ().move(X, Y + 1);
                        mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_Z);
                        posicionSeaValida = true;
                    }
                    break;
                case 'A':
                    if (!mapaEnPartida.getMapaCasillasCoord(X - 1, Y).contenidoParaZombie()) {
                        mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_VACIA);
                        this.zombies[i].getPosicionZ().move(X - 1, Y);
                        mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_Z);
                        posicionSeaValida = true;
                    }
                    break;
                case 'D':
                    if (!mapaEnPartida.getMapaCasillasCoord(X + 1, Y).contenidoParaZombie()) {
                        mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_VACIA);
                        this.zombies[i].getPosicionZ().move(X + 1, Y);
                        mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_Z);
                        posicionSeaValida = true;
                    }
                    break;
                default:
                    break;
            }
            direccionAleatoria = direccionRandom();
            intentos--;

            if (intentos == 0 && !posicionSeaValida) {

                for (int j = 1; j < 5 && !posicionSeaValida; j++) {

                    switch (j) {
                        case 1:
                            if (!mapaEnPartida.getMapaCasillasCoord(X, Y - 1).contenidoParaZombie()) {
                                mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_VACIA);
                                this.zombies[i].getPosicionZ().move(X, Y - 1);
                                mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_Z);
                                posicionSeaValida = true;
                            }
                            break;

                        case 2:
                            if (!mapaEnPartida.getMapaCasillasCoord(X, Y + 1).contenidoParaZombie()) {
                                mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_VACIA);
                                this.zombies[i].getPosicionZ().move(X, Y + 1);
                                mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_Z);
                                posicionSeaValida = true;
                            }
                            break;
                        case 3:
                            if (!mapaEnPartida.getMapaCasillasCoord(X - 1, Y).contenidoParaZombie()) {
                                mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_VACIA);
                                this.zombies[i].getPosicionZ().move(X - 1, Y);
                                mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_Z);
                                posicionSeaValida = true;
                            }
                            break;

                        case 4://D
                            if (!mapaEnPartida.getMapaCasillasCoord(X + 1, Y).contenidoParaZombie()) {
                                mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_VACIA);
                                this.zombies[i].getPosicionZ().move(X + 1, Y);
                                mapaEnPartida.getMapaCasillas(this.zombies[i].getPosicionZ()).setTipoCasilla(Casilla.TIPO_Z);
                                posicionSeaValida = true;
                            }
                            break;
                    }
                }

            }
        }
    }
}

/**
 * Imprime el mapa actualizado
 *
 * @return
 */
public String imprimirMapa() {
    return this.mapaEnPartida.toString();
}

/**
 * Comprueba las vidas del superviviente
 *
 * @return heMuerto
 */
public boolean comprobarVidas() {
    boolean heMuerto = true;
    for (int i = 0; i < this.zombies.length; i++) {
        if (this.superviviente.getPosicionS().equals(this.zombies[i].getPosicionZ())) {
            setVidasPartida(getVidasPartida() - 1);
            heMuerto = false;

        }

    }
    return heMuerto;
}

/**
 * Imprime los puntos al final de la partida
 */
public void imprimirPuntosAlFinalDePartida() {
    System.out.print("Has conseguido :" + getPuntos() + " puntos.");
    System.out.println("");
}

/**
 * Reinicia la partida cuando el superviviente muere, manteniendo el mapa
 * los puntos y las vidas.
 */
public void reiniciarPartida() {
    for (int i = 0; i < mapaEnPartida.getMapaCasilla().length; i++) {
        for (int j = 0; j < mapaEnPartida.getMapaCasilla()[i].length; j++) {
            if (mapaEnPartida.getMapaCasilla()[i][j].getTipoCasilla() == Casilla.TIPO_S || mapaEnPartida.getMapaCasilla()[i][j].getTipoCasilla() == Casilla.TIPO_Z) {
                mapaEnPartida.getMapaCasilla()[i][j].setTipoCasilla(Casilla.TIPO_VACIA);
            }
        }
    }

    this.superviviente.setPosicionS(this.superviviente.movSuperviviente(mapaEnPartida));
    for (int i = 0; i < 3; i++) {
        this.zombies[i].setPosicionZ(this.zombies[i].moverZombie(mapaEnPartida));
    }
}

/**
 * Genera una salida cuando el superviviente recoge todos los items
 */
public void salida() {
    mapaEnPartida.getMapaCasillasCoord(4, 0).setTipoCasilla(Casilla.TIPO_SALIDA);
}

/**
 * Comprueba que el superviviente ha llegado a la salida
 *
 * @return
 */
public boolean heSalido() {
    boolean heSalido = false;
    if (this.superviviente.getPosicionS().equals(mapaEnPartida.getMapaCasillasCoord(4, 0).getLocCasilla())) {
        heSalido = true;
        mapaEnPartida.getMapaCasillasCoord(4, 0).setTipoCasilla(Casilla.TIPO_S);
        mapaEnPartida.getMapaCasillasCoord(4, 1).setTipoCasilla(Casilla.TIPO_VACIA);
    }
    return heSalido;

}

}

CLASS 4:

private Point posicionS = new Point();
private Point posicionSFutura = new Point();

//**Constructor
public Superviviente(Tablero mapaCasillas) {
    boolean busca = true;
    while (busca) {
        int Y = (int) (Math.random() * mapaCasillas.getMapaCasilla().length);
        int X = (int) (Math.random() * mapaCasillas.getMapaCasilla()[0].length);
        posicionSFutura = new Point(X, Y);
        Casilla casillaAComprobar = mapaCasillas.getMapaCasillas(posicionSFutura);
        if (!casillaAComprobar.hayItem() && !casillaAComprobar.hayLimite()) {

            posicionS = new Point(X, Y);
            mapaCasillas.getMapaCasillas(this.getPosicionS()).setTipoCasilla(Casilla.TIPO_S);
            busca = false;
        }
        if (this.posicionS.x > mapaCasillas.getMapaCasilla()[0].length || this.posicionS.x < 0) {
            busca = true;

        } else if (this.posicionS.y > mapaCasillas.getMapaCasilla().length || this.posicionS.y < 0) {
            busca = true;
        }
    }

}

/**
 * Este metodo nos devolverá la posicion del superviviente para usarla con
 * los zombies
 *
 * @param mapaCasillas
 * @return posicionS
 */
public Point movSuperviviente(Tablero mapaCasillas) {
    boolean busca = true;
    while (busca) {
        int Y = (int) (Math.random() * mapaCasillas.getMapaCasilla().length);
        int X = (int) (Math.random() * mapaCasillas.getMapaCasilla()[0].length);
        posicionSFutura = new Point(X, Y);
        Casilla casillaAComprobar = mapaCasillas.getMapaCasillas(posicionSFutura);
        if (!casillaAComprobar.hayItem() && !casillaAComprobar.hayLimite()) {
            posicionS = new Point(X, Y);
            mapaCasillas.getMapaCasillas(this.getPosicionS()).setTipoCasilla(Casilla.TIPO_S);
            busca = false;
        }
    }
    return posicionS;
}

/**
 * Gets y Sets de superviviente
 *
 */
public void setPosicionS(Point posicionS) {
    this.posicionS = posicionS;
}

public void setPosicionSFutura(Point posicionSFutura) {
    this.posicionSFutura = posicionSFutura;
}

public Point getPosicionS() {
    return posicionS;
}

public Point getPosicionSFutura() {
    return posicionSFutura;
}

}

CLASS 5:

// Atributos de tablero
private Casilla[][] mapaCasillas;
private int itemsTablero;

//Contructor
public Tablero() {
    double lmte = Casilla.TIPO_LIMITE;
    double item = Casilla.TIPO_ITEM;
    double nada = Casilla.TIPO_VACIA;
    double[][] casillasNum = new double[][]{
        {lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte},
        {lmte, nada, lmte, lmte, nada, nada, nada, nada, nada, nada, nada, nada, nada, nada, item, lmte},
        {lmte, nada, lmte, lmte, item, lmte, lmte, lmte, nada, nada, nada, lmte, lmte, lmte, nada, lmte},
        {lmte, nada, lmte, lmte, nada, nada, nada, nada, nada, nada, nada, nada, nada, nada, nada, lmte},
        {lmte, nada, lmte, lmte, nada, lmte, item, lmte, lmte, lmte, lmte, lmte, item, lmte, nada, lmte},
        {lmte, nada, nada, nada, nada, lmte, nada, nada, nada, nada, nada, nada, nada, lmte, nada, lmte},
        {lmte, lmte, lmte, lmte, item, lmte, lmte, lmte, item, lmte, item, lmte, lmte, lmte, nada, lmte},
        {lmte, lmte, lmte, lmte, nada, lmte, item, nada, nada, nada, nada, nada, nada, lmte, nada, lmte},
        {lmte, lmte, lmte, lmte, nada, nada, nada, lmte, lmte, lmte, lmte, lmte, nada, item, nada, lmte},
        {lmte, lmte, lmte, lmte, nada, lmte, nada, nada, nada, nada, nada, nada, nada, lmte, nada, lmte},
        {lmte, lmte, lmte, lmte, nada, lmte, lmte, lmte, nada, lmte, item, lmte, lmte, lmte, nada, lmte},
        {lmte, item, nada, nada, nada, lmte, nada, nada, nada, lmte, nada, nada, item, lmte, nada, lmte},
        {lmte, nada, lmte, lmte, nada, lmte, nada, lmte, lmte, lmte, lmte, lmte, nada, lmte, nada, lmte},
        {lmte, nada, nada, nada, nada, item, nada, nada, nada, nada, nada, nada, nada, nada, nada, lmte},
        {lmte, nada, lmte, lmte, nada, lmte, lmte, lmte, item, lmte, nada, lmte, lmte, lmte, nada, lmte},
        {lmte, nada, nada, nada, nada, nada, nada, nada, nada, lmte, nada, nada, nada, nada, nada, lmte},
        {lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte}
    };

    mapaCasillas = new Casilla[casillasNum.length][casillasNum[0].length];

    for (int i = 0; i < casillasNum.length; i++) {
        for (int j = 0; j < casillasNum[i].length; j++) {
            Point point = new Point(j, i);
            if (casillasNum[i][j] == lmte) {
                mapaCasillas[i][j] = new Casilla(lmte);
                this.mapaCasillas[i][j].setLocCasilla(point);
            } else if (casillasNum[i][j] == item) {
                mapaCasillas[i][j] = new Casilla(item);
                this.mapaCasillas[i][j].setLocCasilla(point);
                setItemsTablero(getItemsTablero() + 1);

            } else {
                mapaCasillas[i][j] = new Casilla(nada);
                this.mapaCasillas[i][j].setLocCasilla(point);
            }

        }
    }
}

public Tablero(int prueba) {

}

public String toString() {
    String tablero = "";
    for (int i = 0; i < this.mapaCasillas.length; i++) {
        for (int j = 0; j < this.mapaCasillas[i].length; j++) {
            tablero += this.mapaCasillas[i][j];
        }
        tablero += "\n";
    }
    return tablero;
}

// Gets y Sets de tablero
public Casilla getMapaCasillas(Point coord) {

    return this.mapaCasillas[(int) coord.getY()][(int) coord.getX()];

}

//Aqui nos dará una casilla dandole dos coordenadas.
public Casilla getMapaCasillasCoord(int X, int Y) {

    return this.mapaCasillas[Y][X];
}

//Estos gets dado un Point  devuelve la casilla indicada segun la posicion
public Casilla getMapaCasillasW(Point coord) {

    return this.mapaCasillas[(int) coord.getY() - 1][(int) coord.getX()];

}

public Casilla getMapaCasillasS(Point coord) {

    return this.mapaCasillas[(int) coord.getY() + 1][(int) coord.getX()];

}

public Casilla getMapaCasillasA(Point coord) {

    return this.mapaCasillas[(int) coord.getY()][(int) coord.getX() - 1];

}

public Casilla getMapaCasillasD(Point coord) {

    return this.mapaCasillas[(int) coord.getY()][(int) coord.getX() + 1];

}

// Este get me devuelve un array de Casillas
public Casilla[][] getMapaCasilla() {
    return this.mapaCasillas;
}

public int getItemsTablero() {
    return itemsTablero;
}

public void setMapaCasillas(Casilla[][] mapaCasillas) {
    this.mapaCasillas = mapaCasillas;
}

public void setItemsTablero(int itemsTablero) {
    this.itemsTablero = itemsTablero;
}

}

CLASS 6:

// Atributos de zombie
private Point posicionZ = new Point();
private Point posicionZFutura = new Point();

// gets y sets de zombie
public Point getPosicionZ() {
    return posicionZ;
}

public void setPosicionZ(Point posicionZ) {
    this.posicionZ = posicionZ;
}

public Point getPosicionZFutura() {
    return posicionZFutura;
}

public void setPosicionZFutura(Point posicionZFutura) {
    this.posicionZFutura = posicionZFutura;
}

//Constructor
public Zombies(Tablero mapaCasillas, Point S) {
    boolean busca = true;
    int buscando = 0;
    while (busca) {
        int Y = (int) (Math.random() * (mapaCasillas.getMapaCasilla().length));
        int X = (int) (Math.random() * (mapaCasillas.getMapaCasilla()[0].length));
        posicionZFutura = new Point(X, Y);
        Casilla casilla = mapaCasillas.getMapaCasillas(posicionZFutura);

        if (!casilla.hayItem() && !casilla.hayLimite() && casilla.getTipoCasilla() != Casilla.TIPO_S) {
            posicionZ = new Point(X, Y);
            mapaCasillas.getMapaCasillas(this.getPosicionZ()).setTipoCasilla(Casilla.TIPO_Z);
            busca = false;

        }
    }
}

/**
 * Metodo para mover los zombies de posicion, cuando muere el superviviente
 *
 * @param mapaCasillas
 * @return
 */
public Point moverZombie(Tablero mapaCasillas) {
    boolean busca = true;
    while (busca) {
        int Y = (int) (Math.random() * (mapaCasillas.getMapaCasilla().length));
        int X = (int) (Math.random() * (mapaCasillas.getMapaCasilla()[0].length));
        posicionZFutura = new Point(X, Y);
        Casilla casilla = mapaCasillas.getMapaCasillas(posicionZFutura);

        if (!casilla.hayItem() && !casilla.hayLimite() && casilla.getTipoCasilla() != Casilla.TIPO_S) {
            posicionZ = new Point(X, Y);
            mapaCasillas.getMapaCasillas(this.getPosicionZ()).setTipoCasilla(Casilla.TIPO_Z);
            busca = false;
        }

    }
    return this.posicionZ;
}

}

Forgive for the extension of the code, but it's a big game.

    
asked by kitkat 02.02.2017 в 18:38
source

1 answer

4

There are two main ways to find errors in complex programs in java, both with a different approach.

The first one is the exception, which you can use to get a stacktrace , which is a list of the methods executed before the error occurred, also informing you if there are previous errors that could be the cause of the error in question.

The second one is strategically placing a form of logging (either with 'System.out.println (...) or with a Logger like slf4j ).

To offer you help to help yourself here, I recommend you to place some control points System.out.println(String.format("lamada a %s con %s")); where you expect the code to pass to visualize where your code goes and how many times it repeats. Then you can "lock" your problem with more checkpoints if necessary.

In a case of an unexpected undefined loop you have another way to visualize what is happening, causing a forced exception in this way:

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author snolde
 *
 */
public class ForcedBreak {

    private static AtomicInteger iterations = new AtomicInteger(0);

    public static void breakAfter(int max, String breakpoint) throws ForcedBreakException{
        if (iterations.incrementAndGet() > max) throw new ForcedBreakException(breakpoint);
    }

    public static class ForcedBreakException extends Exception{

        public ForcedBreakException(String breakpoint){
            super(breakpoint);
        }

    }
}

With this kind of utility you can place points in your code where the execution is interrupted that gives you the possibility to receive a stacktrace that gives you more information about the flow. Ways to use it can be as simple as:

// agrega una etiqueta de tu gusto y interrumpe la ejecución después de 1000 iteraciones
ForcedBreak.breakAfter(1000, "in método moverZombie(...)");

or you can continue with the execution while also receiving a stacktrace with:

try{
    ForcedBreak.breakAfter(1000, "in método moverZombie(...)");
} catch (ForcedBreakException e) {
    e.printStackTrace();
    // aquí puedes agregar todas las informaciones que te conviene sobre el estado de tus objetos 
}

Wait until you're useful.

The same can be done with debugging tools that typically come with your IDE, but I leave you this simple way until you had time to learn more about debugging art.

    
answered by 02.02.2017 / 20:27
source