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
最佳答案
要使语法错误消失并为distanceTraveled
分配值,请修改public Water update(int time)
方法,如下所示:
public Water update(int time) {
graphic.draw();
distanceTraveled = 1; // assign a value before returning
return Water.this;
}
也许您应该阅读一些有关Java的知识并进行一些教程,因为这是非常基础的内容(至少在我没有弄错的情况下)。