Delfino

Ecco il codice per fare andare a zig-zag il delfino:

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class delfino  extends Animal
{
int i=0;
int u=0;

    public void act()
    {
         if (atWorldEdge()){
             turn(-180);
        }
            if(u<30){
                sali();
            }
            u++;
            if(u>41){
                stai();
            }
            u++;
            if(u>61){
                scendi();
            }
            if(u>80){
                u=0;
                ritorna();
            }

}
public void sali(){
            if(i==0){
                turn(-45);
                i++;}
                move();
                u++;
            }
public void stai(){
            if(i==1){
                turn(45);
                i++;
            }
            move();
            u++;
    }
public void scendi(){
            if(i==2){
                turn(45);
                i++;
            }
            u++;
            move();
}
public void ritorna(){
    if(i==3){
        turn(-45);
        i=0;
    }
}
}

Commenti