0

コンパイルを押すたびに、プライベートがどこにあるかに関係なく、違法な式の開始が表示されます。コードは次のとおりです。

    /**
     * Act - do whatever the PlatformJumper wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(inTheAir)
        {
            fall();
        } else {
            getCommand();
        }
        move();

        if(isTouching(snowball.class))
        {
            get (snowball.class);
        }    

    private void run (String direction)
    {
        if(direction=="left")
            deltaX = walkSpeed*-1;
        else
            deltaX = walkSpeed;
    }

    private void stop ()
    {
        deltaX = 0;
    }

    private void jump()
    {
        deltaY += jumpHeight;
        inTheAir = true;
    }

    /*
     * fall() will be called whenever BallGuy is in the air. Decreases the deltaY by 1, creating
     * gravity.
     */
    private void fall()
    {
        deltaY-=fallSpeed;
    }

    private void move()
    {
        double newX = getX() + deltaX;
        double newY = getY() - deltaY;

        Actor platformBelow = getOneObjectAtOffset(0, groundHeight + 5, Platform.class);
        Actor platformAbove = getOneObjectAtOffset(0, -(groundHeight + 5), Platform.class);
        Actor platformToRight = getOneObjectAtOffset(sideWidth+5, 0, Platform.class);
        Actor platformToLeft = getOneObjectAtOffset(-(sideWidth+5), 0, Platform.class);
        if(platformBelow!=null)
        {
            if(deltaY<0)
            {
                deltaY = 0;
                inTheAir = false;
                GreenfootImage platformImage = platformBelow.getImage();
                int topOfPlatform = platformBelow.getY() - platformImage.getHeight()/2;
                newY = topOfPlatform - groundHeight;
            }
        }else if(getY() >= worldHeight - groundHeight) {
            if(deltaY < 0)
            {
                deltaY = 0;
                inTheAir = false;
                newY = worldHeight - groundHeight;
            }
        } else {
            inTheAir = true;
        }
        if(platformAbove != null)
        {
            if(deltaY>0)
            {
                deltaY=0;

                GreenfootImage platformImage = platformAbove.getImage();
                int bottomOfPlatform = platformAbove.getY() + platformImage.getHeight()/2;
                newY = bottomOfPlatform + groundHeight;
            }
        }
        if(getX()<=sideWidth)
        {
            deltaX = Math.abs(deltaX);
        }
        if(getX()>=worldWidth-sideWidth)
        {
            deltaX = Math.abs(deltaX) * -1;
        }
        if(platformToRight!=null)
        {
            deltaX = Math.abs(deltaX) * -1;
        }
        if(platformToLeft!=null)
        {
            deltaX = Math.abs(deltaX);
        }
        setLocation((int)newX,(int)newY);
    }

    private void getCommand()
    {
        if(Greenfoot.isKeyDown("left"))
        {
            run("left");
        } else if (Greenfoot.isKeyDown("right"))
        {
            run("right");
        } else 
        {
            stop();
        }

        if(Greenfoot.isKeyDown("up"))
        {
            jump();
        }
    }
}
4

1 に答える 1

0
import greenfoot.*;

/**
 * Write a description of class BallGuy here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class BallGuy extends
{
    public BallGuy()
    {
    }

コードの先頭に次のようなものがあるはずです。現在、コンパイラは、コードの末尾に余分な括弧があると認識しています。あなたは質問のためにそれを省いたと思います。

また:

最初のプライベート メソッドの上の行に括弧を追加します。act() メソッドは閉じられていません。

public void act() 
    {
        if(inTheAir)
        {
            fall();
        } else {
            getCommand();
        }
        move();

        if(isTouching(snowball.class))
        {
            get (snowball.class);
        }    
    }

private void run (String direction)
{
    if(direction=="left")
        deltaX = walkSpeed*-1;
    else
        deltaX = walkSpeed;
}

そのように。

于 2015-10-01T21:31:55.367 に答える