import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * This class defines a crab. Crabs live on the beach. * @Author Aled Evans * @version 1.0 */ public class Crab extends Animal { private GreenfootImage image1 = new GreenfootImage("crab.png"); private GreenfootImage image2 = new GreenfootImage ("crab2.png"); private Score score; *** private int counterx = 0; public Crab (Score pointcounter) *** { score = pointcounter; *** } public void act() { movement(); counterx = counterx + 1; if(counterx==5){ switchImage(); counterx = 0; } lookForWorms(); } public void lookForWorms() { if(canSee(Worm.class)){ eat(Worm.class); Greenfoot.playSound("slurp.wav"); score.add(1); } if(score.getValue() == 5){ Greenfoot.playSound("fanfare.wav"); Greenfoot.stop(); } } public void movement() { move(); if( atWorldEdge()){ turn(5); } if(Greenfoot.isKeyDown("left")){ turn (-12); } if(Greenfoot.isKeyDown("right")){ turn (12); } } public void switchImage() { if(getImage()== image1){ setImage(image2); }else { setImage(image1); } } }