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

2018/12/18

Updating Money score.

1
2
DragonL68 DragonL68

2018/12/20

#
here's the full code
public class Shop extends Objects
{
    private Actor btnBF109 = new bf109price();
    private Actor btnHE162 = new He162price();
    private Actor btnKI67 = new Ki67price();
    private Actor btnmeteor = new Meteorprice();
    private Actor btnmitchell = new Mitchellprice();
    private Actor btnspitfire = new Spitfireprice();
    private Actor btnyak = new Yakprice();
    int geld;
    protected void addedToWold(World world)
    {
        adjustGeld(20000);
    }
    /**
     * Act - do whatever the Shop wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {  
       if(Greenfoot.mouseClicked(this)){
            getWorld().addObject(btnHE162,500 ,400);
            getWorld().addObject(btnKI67,500 ,465);
            getWorld().addObject(btnmeteor,500 ,537);
            getWorld().addObject(btnmitchell,500 ,604);
            getWorld().addObject(btnspitfire,500 ,660);
            getWorld().addObject(btnyak,500 ,700);
            getWorld().addObject(btnBF109,500 ,750);
       }
       if(Greenfoot.mouseClicked(getWorld())){
           getWorld().removeObject(btnHE162);
           getWorld().removeObject(btnKI67);
           getWorld().removeObject(btnmeteor);
           getWorld().removeObject(btnmitchell);
           getWorld().removeObject(btnspitfire);
           getWorld().removeObject(btnyak);
           getWorld().removeObject(btnBF109);
       }
       if (Greenfoot.mouseClicked(btnBF109))
       {
            adjustGeld(-500);
            getWorld().addObject(new BF109(), 250, 485);
       }
    }    
    public void adjustGeld(int adjustment)
    {
        geld += adjustment;
        getWorld().showText("Geld: "+geld, 280, 400);
        getWorld().showText("$", 335, 400);
    }
}
danpost danpost

2018/12/20

#
DragonL68 wrote...
public class bf109price extends Shop
The clickable objects are not shops, but, in essence, buttons. Their classes should extend the Actor class.
You need to login to post a reply.
1
2