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!
Antwoorden Opdracht 4.9
-
- Berichten: 8
- Lid geworden op: 06-02-2017 16:55
Antwoord
Helaas niet in delen
Code voor de haai
Code om de haai toe te voegen
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: 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);
}
}
-
- Berichten: 2
- Lid geworden op: 09-02-2017 15:41
zonder geluid
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);
}
}
}
/**
* 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);
}
}
}