预期的标识符“私人玩家投掷者;”

时间:2015-09-20 12:32:28

标签: java identifier

我正在编写我的第一个游戏,当我尝试编译时遇到问题。它位于Private Player thrower;下的第5行public class Banan extends Actor。当我编译它时标记线黄色,并在“thrower”之后标记为红色,错误显示<identifier> expected。 但我无法找出问题所在。我希望有一个人可以帮助我。

我的代码如下所示:

import greenfoot.*;

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

    private double exactX;
    private double exactY;

    private final double velX;
    private double velY; 

    Private Player thrower; 

    private int rotation = 0;
    private GreenfootImage original;

    /**
     * Act - do whatever the Banan wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        fly();        
        spin();
    }    

    public Banan(Player thrower, double vx, double vy)
    {
        velX = vx;
        velY = vy;
        this.thrower = thrower;

        original = getImage();
    }   

        private void fly()
    {
        velY -= MinionWorld.GRAVITY;
        moveTo(exactX + velX, exactY - velY);
    }

    private void spin()
    {
        rotation += 8;
        GreenfootImage cur = new GreenfootImage(original);
        cur.rotate(rotation);
        setImage(cur);
    }

    private void moveTo(double x, double y)
    {
        MinionWorld world = (MinionWorld)getWorld();
        if (world.hitsGround(exactX, exactY, x, y))
        {
            world.removeObject(this);
            thrower.landed(x, y);
            world.landed();

        }
        else 
        {
            setExactLocation(x, y);

        }
    }

    public void setLocation(int x, int y)
    {
        exactX = x;
        exactY = y;
        super.setLocation(x, y);
    }

    public void setExactLocation(double x, double y) 
    {
        exactX = x;
        exactY = y;
        super.setLocation((int) (x + 0.5), (int) (y + 0.5));
    }

    public void move()
    {
        int speed = 1;
        {
        if(Greenfoot.isKeyDown("left"))
        setLocation(getX() - speed, getY());
        if(Greenfoot.isKeyDown("right"))
        setLocation(getX() + speed, getY());
        }
    }

    public static double getImpactTime(double radianAngle, double forceFactor)
    {        
        double vx = Player.getVelX(radianAngle, forceFactor);
        double vy = Player.getVelY(radianAngle, forceFactor);

        double impactTime = 2.0 * (vy / MinionWorld.GRAVITY) - 1;

        return impactTime;
    }
}

我现在在另一个类中遇到此错误。我不知道我是否被允许在这里写,如果没有,就这么说。

在我的公共类中,Minion扩展了播放器,当我编译时,出现了这个错误:Minion不是抽象的,并且不会覆盖播放器中的抽象方法startTurn()。

以下是我的播放器代码:

import greenfoot.*;

/**
 * Write a description of class Player here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public abstract class Player extends Actor
{
    /**
     * Act - do whatever the Player wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    

    public static double getVelX(double angleRadians, double forceFactor)
    {
        return Math.cos(angleRadians) * (MinionWorld.MIN_FORCE + forceFactor * (MinionWorld.MAX_FORCE - MinionWorld.MIN_FORCE));
    }

        public static double getVelY(double angleRadians, double forceFactor)
    {
        return -Math.sin(angleRadians) * (MinionWorld.MIN_FORCE + forceFactor * (MinionWorld.MAX_FORCE - MinionWorld.MIN_FORCE));
    }

    public abstract void startTurn();
    {
    }

    public void fire(double angleRadians, double forceFactor)
    {
        final int minDegrees = -180 + MinionWorld.LOWEST_ANGLE;
        final int maxDegrees = -MinionWorld.LOWEST_ANGLE;
        if (angleRadians < Math.toRadians(minDegrees)|| angleRadians > Math.toRadians(maxDegrees))
        {
            throw new IllegalArgumentException("Angle (" + Math.toDegrees(angleRadians) + ") outside acceptable range: " + minDegrees + " to " + maxDegrees);
        }
        if (forceFactor < 0 || forceFactor > 1)
        {
            throw new IllegalArgumentException("Force factor out of range");
        }
        double vx = getVelX(angleRadians, forceFactor);
        double vy = getVelY(angleRadians, forceFactor);
        getWorld().addObject(new Banan(this, vx, vy), getX(), getY());
    }

        public void landed(double x, double y)
    {
    }

        public void move()
    {
        int speed = 1;
        int x = getX();
        {
        if(x>30&&Greenfoot.isKeyDown("UP"))
        setLocation(getX() - speed, getY());
        if(x<770&&Greenfoot.isKeyDown("DOWN"))
        setLocation(getX() + speed, getY());
        }
    }
}

1 个答案:

答案 0 :(得分:2)

一个简单的拼写错误:

p rivate P rivate; Java是一种区分大小写的语言。