对于课程,我应该扩展错误参与者以制作一个在网格上生成 M 的错误。这是我到目前为止所拥有的,但错误并没有朝指定的方向转动。相反,它是一个正方形。对我做错了什么有帮助吗?
import info.gridworld.actor.Bug;
import info.gridworld.grid.Location;
public class MBug extends Bug{
private int lineLength;
private int steps;
private int line;
public MBug(int length)
{
setDirection(Location.NORTH);
steps = 0;
line = 1;
lineLength = length;
}
public void act(){
if (line <= 4 && steps < lineLength){
if (canMove()){
move();
steps++;
}
}else if (line == 2){
setDirection(Location.SOUTHEAST);
steps = 0;
line++;
}else if (line == 3){
setDirection(Location.NORTHEAST);
steps = 0;
line++;
}else if (line == 4){
setDirection(Location.SOUTH);
steps = 0;
line++;
}
}
}