【发布时间】:2018-12-14 18:30:07
【问题描述】:
在开始之前,我想提一下我是编程新手,而且我真的很糟糕。如果您能想到任何可能导致我的问题的原因,那么可能值得检查。
我正在制作一个游戏,其中用户控制鲨鱼并且必须四处走动,吃鱼并躲避垃圾。用户每吃一条鱼就得一分。我遇到了一个问题,程序说它找不到方法,我似乎无法弄清楚。
这就是错误所在。它属于 Food 类(鱼,鲨鱼吃什么):
Actor foodHit = getOneIntersectingObject(Shark.class);
if(foodHit!=null)
{
World MyWorld = (World)MyWorld;
Counter counter = World.getCounter();
// The error is apparently in this line above, here's the error code: "cannot find symbol - method getCounter()".
counter.addScore();
MyWorld.removeObject(this);
}
这是有问题的方法,它在 MyWorld 类中:
public Counter getCounter()
{
return counter;
}
如果您要求,我可以回答任何问题并显示更多行。 我知道有时与新朋友打交道很令人沮丧,所以我很抱歉。 任何帮助都会很棒,感谢阅读!
【问题讨论】:
-
您使用的是 Java,而不是 JavaScript btw :)
-
由于您是编程新手,您可能希望 Food 类能够在全球范围内引用鲨鱼的世界。你在这里做什么:
World MyWorld = (World)MyWorld;MyWorld 在你将它投射到 World 之前是什么类型? -
我正在观看他们输入的教学视频。我不明白那条线想要做什么。