0
對於我來說,我應該擴展bug角色來製作一個在網格上產生M的bug。這是我迄今爲止的,但錯誤不會按照指定的方向。相反,它使方形。任何幫助我做錯了什麼?GridWorld Mbug演員
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++;
}
}
}