import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class SnakeHead here.
*
* @author (Valentijn & Oline)
* @version (Final Draft)
*/
public class SnakeHead extends Animal
{
/**
* Act - do whatever the SnakeHead wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
int count = 0;
int Diamondseaten = 0;
if (Greenfoot.isKeyDown("left")) {
if (canSee (Wall.class))
{}
turn(-25);
}
if (Greenfoot.isKeyDown("right")){
if (canSee (Wall.class))
{}
turn(25);
}
if (Greenfoot.isKeyDown("up")){
if (canSee (Wall.class))
{
World world = getWorld();
getWorld().removeObjects(getWorld().getObjects(null));
}
move();
}
if (Greenfoot.isKeyDown("down")){
if (canSee (Wall.class))
{}
move(-2);
}
if (canSee(Diamond.class))
{
removeTouching (Diamond.class);
}
if (isTouching(Wall.class))
{
Greenfoot.stop();
Greenfoot.setWorld(new SnakeWorld());
}
if(count > 20){
move();
count = 0;
}
if(Diamondseaten < 1){
count += 1;
}else if(Diamondseaten < 2){
count += 2;
}else if(Diamondseaten < 3){
count += 2.5;
}else if(Diamondseaten < 4){
count += 4;
}else if(Diamondseaten >= 4){
count += 5;
}
int speed = 20;
if(count == speed){
getWorld().addObject(new SnakeTail(Diamondseaten*speed), getX(), getY());
}
}
}
