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

2019/2/1

Wombats and Leafs Limit Question

SilentHunter115 SilentHunter115

2019/2/1

#
Is it possible to code the wombat to have a set number of leafs it can eat, like having a set number of two leafs it can eat, move to the next leaf, not eat it, and move on like normally?
/**
     * Eat a leaf (if there is one in our cell).
     */
    public void eatLeaf()
    {
        Actor leaf = getOneObjectAtOffset(0, 0, Leaf.class);
        if (leaf != null) {
            // eat the leaf...
            getWorld().removeObject(leaf);
            leavesEaten = leavesEaten + 1; 
        }
    }
danpost danpost

2019/2/1

#
You could add the following as the first line in the foundLeaf method, to prevent "seeing" the leaf when count is 2:
if (leavesEaten == 2) return false;
You need to login to post a reply.