package entities;

import java.awt.Color;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import snake.Screen;

public class Food extends Entity {
  private final int SIZE = Snake.SIZE;
  private int x, y;
  public Color color;

  public Food() {
    r = new Random();
    color = chooseColour();
    update();
  }

  @Override
  public void draw(Graphics2D g2d) {
    g2d.setColor(color);
    g2d.fillOval(cellX, cellY, SIZE, SIZE);
  }

  @Override
  public void update() {
    color = chooseColour();
    x = r.nextInt(Screen.WIDTH);
    y = r.nextInt(Screen.HEIGHT);
    cellX = x / SIZE * SIZE;
    cellY = y / SIZE * SIZE;
    for (Entity wall : Screen.walls) {
      if (collide(wall)) {
        update();
      }
    }
    for (Entity bodyPiece : Snake.body) {
      if (collide(bodyPiece)) {
        update();
      }
    }
    if (collide(Snake.self)) {
      update();
    }
  }

  private Color chooseColour() {
    float a = r.nextFloat() / 4 + 0.7f;
    float b = r.nextFloat() / 4 + 0.1f;
    float c = r.nextFloat() / 4 + 0.1f;
    List<Float> colours = new ArrayList<Float>();
    colours.add(a);
    colours.add(b);
    colours.add(c);
    Collections.shuffle(colours);
    return new Color(
        colours.get(0),
        colours.get(1),
        colours.get(2));
  }
}

@@ -67,89 +67,8 @@
 2D;%0A
-import java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A
 impo
@@ -88,16 +88,16 @@
 Random;%0A
+
 %0Aimport 
@@ -226,16 +226,41 @@
 r color;
+%0A  private float h, s, b;
 %0A%0A  publ
@@ -297,37 +297,108 @@
 ();%0A    
-color = chooseColour(
+s = 1.0f;%0A    b = 1.0f;%0A    h = r.nextFloat();%0A    color = new Color(Color.HSBtoRGB(h, s, b)
 );%0A    u
@@ -579,29 +579,65 @@
     
-color = chooseColour(
+h += 0.03f;%0A    color = new Color(Color.HSBtoRGB(h, s, b)
 );%0A 
@@ -1007,24 +1007,24 @@
   update();%0A
+
     %7D%0A  %7D%0A%0A 
@@ -1024,404 +1024,7 @@
 %0A  %7D
-%0A%0A  private Color chooseColour() %7B%0A    float a = r.nextFloat() / 4 + 0.7f;%0A    float b = r.nextFloat() / 4 + 0.1f;%0A    float c = r.nextFloat() / 4 + 0.1f;%0A    List%3CFloat%3E colours = new ArrayList%3CFloat%3E();%0A    colours.add(a);%0A    colours.add(b);%0A    colours.add(c);%0A    Collections.shuffle(colours);%0A    return new Color(%0A        colours.get(0),%0A        colours.get(1),%0A        colours.get(2));%0A  %7D
 %0A%7D%0A

Make colors cycle