public class Water {
private Graphic graphic;
private float speed;
private float distanceTraveled;
public Water(float x, float y, float direction)
{
speed = 0.7f;
graphic = new Graphic();
graphic.setType("WATER");
graphic.setX(x);
graphic.setY(y);
direction = graphic.getDirection(); //direction from Hero as water is fired
}
public Water update(int time)
{
graphic.draw();
return Water.this;
distanceTraveled; // this is where the error occured...
}
}
当我尝试调用 distanceTraveled
时,出现以下错误:
语法错误,插入“VariableDeclarators”以完成 LocalVariableDeclaration
原文由 Mike 发布,翻译遵循 CC BY-SA 4.0 许可协议
要使语法错误消失并将值分配给
distanceTraveled
修改方法public Water update(int time)
如下:也许您应该阅读一些有关 Java 的内容并做一些教程,因为这是非常基础的东西(至少如果我没有误会您的话)。