How to properly print a String vector that stores ASCII images?

' main package;

 import java.util.Scanner;


 public class Juego {

 ImagenP images;
 String[] imgPokemons;


String tecla;

public Juego() {
    images = new ImagenP();

    imgPokemons = new String[5];

}

//Creando el método Agregar pokemon.
public void seleccionar() {

    Pokemon pokemon[] = new Pokemon[5];

    pokemon[0] = new Pokemon(" Bulbasaur", "vivo", 10);
    pokemon[1] = new Pokemon(" Charizard", "vivo", 10);
    pokemon[2] = new Pokemon(" Squirtle", "vivo", 10);
    pokemon[3] = new Pokemon(" Charmander", "vivo", 10);
    pokemon[4] = new Pokemon(" Spearow", "vivo", 10);

    imgPokemons[0] = images.pok1;
    imgPokemons[1] = images.pok2;
    imgPokemons[2] = images.pok3;
    imgPokemons[3] = images.pok4;
    imgPokemons[4] = images.pok5;

    for (Pokemon pokemon1 : pokemon) {
        int pok = 0;
        System.out.println((pok + 1) + pokemon1.mensaje());


    int i;
    for (i = 0; i < imgPokemons.length; i++) {
        System.out.println( imgPokemons[i]);

    }}
}


 }'

The images are in a separate class.

' main package;

public class ImagenP {

String pok1;
String pok2;
String pok3;
String pok4;
String pok5;

public ImagenP() {
  '

Are very large images that I have best decided to place the photo so that they can see the shapes.

enter the description of the image here

A small menu to ride the game.

public static void main(String[] args) {

   Scanner entrada = new Scanner(System.in);
    int  opcion ;





    do {


        System.out.println("\n****TAMAGOTCHI****");

        System.out.println("1. Seleccionar Pokemon");
        System.out.println("2. Alimentar");
        System.out.println("3. Ejercitar");
        System.out.println("4. Estado");
        System.out.println("5. Matar");
        System.out.println("6. Revivir");
        System.out.println("7. Salir\n");

        System.out.println("Seleccione opción:");
         opcion = entrada.nextInt();

        switch (opcion) {
            case 1:

                seleccion();

                break; 

          default:

        }

    //} while (letra.equals("S") || letra.equals("n"));
    }while (opcion != 7);

}

private static void seleccion() {
    Juego J = new Juego();
    J.seleccionar();
} '

My problem is that it is printing several times an image instead of printing the rest of images that are 5.

 3
Author: angel_elias, 2016-06-07

1 answers

The error must be in class constructor ImagenP because I did a test with the code you placed and there were no problems. Check that you are not assigning the strings with the images to the same attribute pok1, pok2, ...

On the other hand, you can improve this code:

int pok = 0;
for (Pokemon pokemon1 : pokemon) {
    System.out.println((++pok) + pokemon1.mensaje());
    for (int i = 0; i < imgPokemons.length; i++) {
        System.out.println(imgPokemons[i]);
    }
}

And in the same main you can do:

switch (opcion) {
    case 1:
        new Juego().seleccionar();
        break;
    default:
        System.out.println("Opción no válida");
        break;
    }

And you remove the method from the end:

private static void seleccion() {
    Juego J = new Juego();
    J.seleccionar();
} 
 1
Author: Alejandro Rangel Celis, 2016-06-07 17:26:33