不知道如何修复此代码。需要做亚军和主班。该程序需要能够随机生成错误的轮次。
到目前为止,这就是我的 RandomBug 课程:
import info.gridworld.actor.Bug;
import java.awt.Color;
public class RandomBug extends Bug
{
public RandomBug()
{
setColor(Color.YELLOW);
}
public RandomBug(Color bugColor)
{
setColor(bugColor);
}
public void turn(int angle)
{
turn(); turn(); turn(); turn();
}
public void turnAround() {
turn();
}
public int turnAngle() {
int angle = 45 * (int) (Math.random() * 8);
int x = angle;
return x;
}
public void act()
{
if (canMove())
move();
else
turnAround();
}
}
这是我的 RandomBugRunner.java:
import java.awt.Color;
import info.gridworld.actor.ActorWorld;
import info.gridworld.actor.Bug;
import info.gridworld.actor.Rock;
import info.gridworld.grid.Location;
public class RandomBugRunner
{
public static void main(String[] args)
{
ActorWorld world = new ActorWorld();
RandomBug bug1 = new RandomBug();
bug1.setColor(Color.blue);
world.add(bug1);
bug1.act();
bug1.turn(bug1.turnAngle());
bug1.turnAround();
world.show();
}
}