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

2019/1/16

Logic errors(?). boomArea no checking to see if bomb has hit class

1
2
Notted Notted

2019/1/17

#
Would it be better to put the game ender inside the collectBomb method?
private int collectBomb(int numOfBombs) 
    {
        Actor bomb;
        bomb = getOneObjectAtOffset(0, 0, Bomb.class);
        if (bomb != null)
        {
           getWorld().removeObject(bomb);
           numOfBombs = numOfBombs + 1;
        }
        if (numOfBombs == 100)
        {
            Greenfoot.setWorld(new MyWorld());
        }
        return numOfBombs;
    }
Is this better or worse? I think its worse, but at lest funcional.
danpost danpost

2019/1/17

#
Notted wrote...
Would it be better to put the game ender inside the collectBomb method? << Code Omitted >> Is this better or worse? I think its worse, but at lest funcional.
It is a bit better. Here, it is even better:
private void collectBomb()
{
    Actor bomb = getOneObjectAtOffset(0, 0, Bomb.class);
    if (bomb != null)
    {
        getWorld().removeObject(bomb);
        numOfBombs = numOfBombs + 1;
        if (numOfBombs == 100) Greenfoot.setWorld(new MyWorld());
    }
}
or this:
private void collectBomb()
{
    Actor bomb = getOneObjectAtOffset(0, 0, Bomb.class);
    if (bomb != null)
    {
        getWorld().removeObject(bomb);
        if (++numOfBombs == 100) Greenfoot.setWorld(new MyWorld());
    }
}
Notted Notted

2019/1/18

#
Thanks!
You need to login to post a reply.
1
2