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

2018/7/26

Having issues with winning the game

jjboy jjboy

2018/7/26

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class flag here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class block0  extends Actor
{
    /**
     * Act - do whatever the flag wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        wan();
        won();
    }
    public boolean wan()
    {
        if(win = true)
        {
            ((Space)getWorld()).makeLevel();
        }
    }
    public void win()
    {

        if (Greenfoot.mouseClicked(null))
        {
            
            won();
        }
        else

        {
            
        }
    }
    public boolean won()
    {
        Actor block0 = getOneIntersectingObject (block0.class); 
        if(block0!=null)
            {
                Actor win = getOneIntersectingObject(block1.class);
                  return win!= null;
                
            }
            else
            {
                Greenfoot.stop();
            }
    }
 
    public block0()
    {
        GreenfootImage image = getImage();
        image.scale(image.getWidth() + 30 , image.getHeight() + 47);
        setImage(image);
    }

}
danpost danpost

2018/7/26

#
To test for equality, use the conditional operator '=='. Line 22 above should be
// either
if (win == true)
// or simply (since 'win' is -- supposedly -- a boolean)
if (win)
I said supposedly because I do not see where a win field is declared within the class.
You need to login to post a reply.