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

2016/1/7

missing something- not changing levels

hoothoot hoothoot

2016/1/7

#
Ok, i know i'm missing something that is preventing this method from setting up level 3, so can someone point it out?
public void Win()
    {
        Enemy enemy = (Enemy) getWorld().getObjects(Enemy.class).get(0);
        Bar ebar = (Bar)getWorld().getObjectsAt(425, 25, Bar.class).get(0);
        Bar bar = (Bar)getWorld().getObjectsAt(125, 25, Bar.class).get(0);
        int LEVELCOUNT = 1;
        if (enemy.GetHealth() <=0)
        {
            WINTIMER++;
            if (WINTIMER>=40)
            {
                LEVELCOUNT++;
                getWorld().removeObject(ebar);
                getWorld().removeObject(bar);
                if(LEVELCOUNT== 2)
                {
                    ((SticksWorld)getWorld()).prepare2();
                    setHealth(-getHealth());
                    setHealth(9001);
                    enemy.SetHealth(10500);
                }
                else if (LEVELCOUNT >= 3)
                {((SticksWorld)getWorld()).prepare3();
                    setHealth(-getHealth());
                    setHealth(9001);
                    enemy.SetHealth(12000);
                }
                WINTIMER = 0;
            }

        }
    }
danpost danpost

2016/1/7

#
Line 6 declares a method variable for LEVELCOUNT. It is not an instance field that will have scope beyond the execution of the method. That is, its value does not exist while the method is not executing and its value can be no more than one (from line 6) plus one (possibly from line 12) -- or two. Therefore, the 'prepare3' method of the SticksWorld class will never execute as the code is now.
You need to login to post a reply.