Antwoorden Opdracht 4.9

Plaats reactie
admin
Site Admin
Berichten: 36
Lid geworden op: 01-02-2017 10:09

Antwoorden Opdracht 4.9

Bericht door admin » 13-02-2017 11:49

Wie voegt hier de goede antwoorden toe? Mooiste is als je van onderdeel a t/m e apart de code neerzet. Bekijk elkaars code en geef feedback!

ReneBruikman
Berichten: 8
Lid geworden op: 06-02-2017 16:55

Antwoord

Bericht door ReneBruikman » 13-02-2017 17:36

Helaas niet in delen

Code voor de haai

Code: Selecteer alles


import greenfoot.*;

/**
 * Write a description of class Shark here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Shark extends Animal
{
    /**
     * Act - do whatever the Shark wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (atWorldEdge()){
          turn(180);  
        }
        else{
            turnRandom(5);
        }
        move();
        if (isTouching(Fish.class)){
            removeTouching(Fish.class);
            Greenfoot.stop();
        }
    }
    public void makeSound () {
        Greenfoot.playSound ("Shark.wav");
    }
}  
Code om de haai toe te voegen

Code: Selecteer alles


import greenfoot.*;  // (Actor, World, Greenfoot, GreenfootImage)

public class WaterWorld extends World
{   
    /**
     * Create the water world. Our world has a size 
     * of 800x600 cells, where every cell is just 1 pixel.
     */
    public WaterWorld() 
    {
        super(800, 600, 1);
        // put a fish in the water
        addObject (new Fish(), 400, 300); 
        addObject (new FleaGreen(), 100, 200); 
        addObject (new FleaGreen(), 600, 500); 
        addObject (new FleaRed(), 500, 100); 
        addObject (new FleaRed(), 200, 400); 
        addObject (new Shark(), 100,100);
    }
}

Oumaima
Berichten: 2
Lid geworden op: 09-02-2017 15:41

zonder geluid

Bericht door Oumaima » 13-03-2017 16:37

import greenfoot.*;

/**
* Write a description of class Shark here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Shark extends Animal
{
/**
* Act - do whatever the Shark wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()

{
move();

if (isAtEdge())
{
turn(180);
}
else
{
turnRandom(5);
haaiEetVis();
}

}
public void haaiEetVis()
{
if (isTouching(Fish.class))
{
removeTouching(Fish.class);
}
}
}

Plaats reactie