This is not about animation.
You need to repaint the Field the snake is running on. repainting it every time you change something. Repainting it every time you add an apple or stone(? - where those in there?).
You can pass arguments to your Component that specify the snake and the obsticales:
public class PanelPlayGround extends JPanel{
private Snake oSnake;
private Obesticales oObsticales;
public PanelPlayGround(final Snake oSnake, final Obsticales oObsticales){
super():
setSnake(oSnake);
setObsticales(oObsticales);
ignition();
}
private void ignition(){
}
public void renewPanel(final Snake oNewSnake, final Obsticales oNewObsticales){
setSnake(oNewSnake);
setObsticales(oNewObsticales);
this.dolayout();
}
}
The Object
Snake
contains basically a list of x/y-values to specify which fields of the grid are occupied by the snake.
The Object
Obsticales
contains a List of Obstical.
Obstical
contains one x/y value and one Enum
ObsticalType
.