Hello there
I'm back again with another problem
I'm now working on a life counter. I don't know if it counts and it doesn't change the images I made.
- create vars
- create base var for Image
- if fault counter hits specific number (3)
- Life counter subs by one
- Fault counter gets reset
- other fault counter gets reset
- If live counter hits specific number (number of lives) a new Image will be set in image var
- Set the var image as image
- if No lives are left
- show message "game over"
- Stop
- Fault counter = static number of faults (3) - other fault counter
- Other fault counter gets added with 1 if that methode gets called by another actor
Is there a problem with the counter it self or the thing to set the images?
Kind regards
Yen
public class Counter extends Actor
{
private int live = 3;
private int fault = 2;
private int aaaa = 0;
private static final int faultF = 2;
/**
* Act - do whatever the Counter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
CalcF();
GreenfootImage image = new GreenfootImage("bbbOrgF11.png");
if(fault <= 0)
{
live--;
fault = 3;
aaaa = 0;
}
if (live == 3)
{
image = new GreenfootImage("bbbOrgF11.png");
}
else
if (live == 2)
{
image = new GreenfootImage("bbbOrgF22.png");
}
else
if (live == 1)
{
image = new GreenfootImage("bbbOrgF33.png");
}
else
if (live == 0)
{
image = new GreenfootImage("bbbOrgF44.png");
}
setImage(image);
if (live == 0)
{
getWorld().addObject(new Message(), getWorld().getWidth()/2, getWorld().getHeight()/2);
Greenfoot.stop();
}
}
private void CalcF()
{
fault = faultF - aaaa;
}
public void sub()
{
aaaa++;
}
}
