Error in Java zombie game

1

I have a large program with 5 classes, in which every time I run this error comes up in NetBeans :

These are the different classes:

-CLASS 1, Batoilkingdead :

public static final int NUMERO_DE_VIDAS = 3;
private static final boolean GAME_OVER = false;

public static void main(String[] args) {
    BatoilkingDead.inicio();
}

public static void inicio() {
//Creacion de las Casillas del JUEGO
    int[][] ResultadoCasillas =           Casillas.creaCasillasEscenarioJuego();
    int[] posicionSuperviviente = Superviviente.creaPosicionSuperviviente(ResultadoCasillas);
    int[][] posicionesDelZombie = Zombies.creaPosicionZombie(ResultadoCasillas);

    do {
        //Muestra el juego llamando a las diferentes clases:
        Partidas.imprimirCasillas(ResultadoCasillas, posicionesDelZombie, posicionSuperviviente);

        String moverSupervivientePorLasCasillas = Partidas.comprobarOrden(Partidas.pedirOrden());
        Superviviente.moverSuperviviente(posicionSuperviviente, posicionesDelZombie, ResultadoCasillas, moverSupervivientePorLasCasillas);

        Zombies.MovimientoZombieAleatorio(ResultadoCasillas, posicionesDelZombie, posicionSuperviviente);
    } while (!GAME_OVER);
  }
}

CLASS 2, Casillas

public static final int TIPO_LIMITE = 2;
public static final int TIPO_ITEM = 3;

public static int[][] creaCasillasEscenarioJuego() {
    int lmte = TIPO_LIMITE;
    int item = TIPO_ITEM;
    int nada = TIPO_VACIA;

    int[][] casillas = new int[][]{
        //0
        {lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte, lmte},
        {lmte, item, item, item, nada, nada, nada, nada, nada, nada, nada, nada, nada, nada, item, lmte},
        {lmte, item, lmte, lmte, item, lmte, lmte, lmte, item, item, item, lmte, lmte, lmte, item, lmte},
        {lmte, item, item, item, item, item, nada, nada, nada, nada, nada, nada, nada, nada, nada, lmte},
        {lmte, item, lmte, lmte, item, lmte, item, lmte, lmte, lmte, lmte, lmte, item, lmte, item, lmte},
        {lmte, item, nada, nada, nada, lmte, nada, nada, nada, nada, nada, nada, nada, lmte, item, lmte},
        {lmte, lmte, lmte, lmte, item, lmte, lmte, lmte, item, lmte, item, lmte, lmte, lmte, item, lmte},
        {lmte, lmte, lmte, lmte, item, lmte, item, item, item, item, item, item, item, lmte, item, lmte},
        {lmte, lmte, lmte, lmte, item, item, item, lmte, lmte, lmte, lmte, lmte, item, item, item, lmte},
        {lmte, lmte, lmte, lmte, item, lmte, nada, nada, nada, nada, nada, nada, nada, lmte, item, lmte},
        {lmte, lmte, lmte, lmte, item, lmte, lmte, lmte, item, lmte, item, lmte, lmte, lmte, item, lmte},
        {lmte, item, item, item, item, lmte, item, item, item, lmte, item, item, item, lmte, item, lmte},
        {lmte, item, lmte, lmte, item, lmte, item, lmte, lmte, lmte, lmte, lmte, item, lmte, item, lmte},
        {lmte, item, item, item, item, item, item, item, item, item, item, item, item, item, item, lmte},
        {lmte, item, lmte, lmte, item, lmte, lmte, lmte, item, lmte, item, lmte, lmte, lmte, item, lmte},
        {lmte, item, item, item, 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}
    };
    return casillas;

}

public static boolean noEsLimite(int[][] casillas, int x, int y) {
    return casillas[x][y] != TIPO_LIMITE;
}

public static boolean hayItem(int[][] casillas, int x, int y) {
    return casillas[x][y] == TIPO_ITEM;

}

public static void vaciarCasilla(int[][] casillas, int x, int y) {
    casillas[x][y] = TIPO_VACIA; //asigna el valor de la casilla vacia

}

public static boolean comprobarVacia(int[][] casillas, int x, int y) {
    return casillas[x][y] == TIPO_VACIA;
}

public static String representacionGrafica(int[][] casillas, int x, int y) {
    String representacion = "";

    switch (casillas[x][y]) {
        case 1:
            System.out.println(" ");
            break;

        case 2:
            System.out.println("                     
asked by kitkat 21.12.2016 в 13:00
source

1 answer

2

The problem you have is that you are changing the coordinates x by y . Typically, you refer to the x as the number of fixes y of n elements. In your case the maximum x is 16 and the maximum y is 15.

When doing:

x = random.nextInt(casillas[0].length);
y = random.nextInt(casillas.length);

and not being a square matrix it overflows you and then to check that it is empty you look it upside down:

casillas[x][y] == TIPO_VACIA;//primero filas y luego columnas

Change those lines by reversing them:

x = random.nextInt(casillas.length);
y = random.nextInt(casillas[0].length);

or check by passing to the method Casillas.comprobarVacia(casillas, y, x) and thus check them changed.

If you do not get that error you already have your answer. That does not mean that according to you have designed the results you draw transposed because I have not seen your code to paint them.

    
answered by 21.12.2016 / 13:55
source