This site requires JavaScript, please enable it in your browser!
Greenfoot back
kaatja
kaatja wrote ...

2012/12/21

Okay, In my scenario people are able to get sick by touching a Mikrobe.class . When they get sick there is an image change and they turn green. I want that the Mikrobe.class only eats the green people. How can I do that?

kaatja kaatja

2012/12/21

#
Heres marge.class, but i need to put the wanted code in Mikrobe.class right?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Homer here.
* 
* @author (your name) 
* @version (a version number or a date)
*/
public class Marge extends Opfer
{
private static final double WALKING_SPEED = 5.0;
/**
* Act - do whatever the Homer wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act() 
{
{

if ( atWorldEdge() )
{
turn(35);
}
if ( Greenfoot.getRandomNumber(100) <10 )
{
turn(5);
}
heal();
move();
meetMikrobe();
if(meetMikrobe())
{
if (Greenfoot.getRandomNumber(100)<50)
{
getsick();
}
}
}
} 



public boolean meetMikrobe()
{
Actor Mikrobe = getOneObjectAtOffset(0, 0, Mikrobe.class) ;
if(Mikrobe != null)
{ 
return true;
}
else
{
return false;
}
}
public void getsick()
{
setImage("ORIGINAL MARGE KRANK.gif");

}

public void heal()
{ if (canSee(Retter.class))
{
setImage("ORIGINAL MARGE.gif");
}
}
}
danpost danpost

2012/12/21

#
You will have to somehow keep track of the current state of the actor; whether it be a boolean that holds a true/false value of the state 'isSick' or a String that holds the current name of the file the image of the actor is set to. The value of this new field can then be used to determine if the actor is currently sick. It will have to be set to 'true' when first contracting a mikrobe.
You need to login to post a reply.