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);
serpiente[serpiente.length-1]=colores[aleatorio];
}
}
In index.jsp
serpiente manolita = new serpiente();
String[] mostrar = null;
mostrar= manolita.getSerpiente();
for (int i = 0; i < mostrar.length ; i++) {
out.print(mostrar[i]);
}