Life of a snake in JSP


I am doing a "game" of a snake, in which it must grow little by little and each part of its body has a color. I have problems with putting the color and I do not know in what way I can enter it. I put the code that I have put in which I get null. My idea was to show a color in the last position. I hope you have explained me well. Thanks in advance

public class serpiente {

    private String[] serpiente;
    private int edad;

    public serpiente() {
        this.serpiente = new String[1];
        this.edad = 1;

    public void colores() {
        String[] colores = {"blue, pink, green, yellow, red"};
        int aleatorio = (int) (Math.random() * colores.length);


In index.jsp

serpiente manolita = new serpiente();
String[] mostrar = null;
mostrar= manolita.getSerpiente();

for (int i = 0; i < mostrar.length ; i++) {
asked by Esther 26.09.2018 в 11:18

1 answer


It seems like you forgot to call the colores() method somewhere.

For example:

serpiente manolita = new serpiente();

Even so, only one segment of the snake will be colored.

answered by 26.09.2018 в 11:25