Java GridWorld Mbug演员
对于类,我应该扩展bug角色来生成一个在网格上生成M的bug。这是我到目前为止所做的,但是bug并没有朝着指定的方向发展。相反,它是一个正方形。我做错了什么有什么帮助吗Java GridWorld Mbug演员,java,gridworld,Java,Gridworld,对于类,我应该扩展bug角色来生成一个在网格上生成M的bug。这是我到目前为止所做的,但是bug并没有朝着指定的方向发展。相反,它是一个正方形。我做错了什么有什么帮助吗 import info.gridworld.actor.Bug; import info.gridworld.grid.Location; public class MBug extends Bug{ private int lineLength; private int steps; private int lin
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++;
}
}
import info.gridworld.actor.Bug;
导入info.gridworld.grid.Location;
公共类MBug扩展Bug{
专用整数线长度;
私有int步骤;
专用内线;
公共MBug(整数长度)
{
设置方向(位置:北);
步长=0;
直线=1;
lineLength=长度;
}
公共无效法案({
如果(行Ta da
这是密码。如果你什么都不懂,请告诉我
import info.gridworld.actor.Bug;
import info.gridworld.grid.Location;
public class MBug extends Bug{
private int lineLength;
private int steps;
/* strokeNum is basically a code to tell the bug which stroke it is on.
* In this case, an 'M' has four strokes:
* up, diagonal down, diagonal up, and then down.
* This method can be used to create any letter,
* but round strokes (C's, R's, etc.) take so many individual strokes that it's almost impossible.
*/
private int strokeNum;
public MBug(int length){
lineLength=length;
steps = 0;
strokeNum=0;
}
public void act(){
if(strokeNum==0){
setDirection(Location.NORTH);
}else if(strokeNum==1){
setDirection(Location.SOUTHEAST);
//This is to shorten the length of this stroke.
steps++;
}else if(strokeNum==2){
setDirection(Location.NORTHEAST);
//This is to shorten the length of this stroke.
steps++;
}else if(strokeNum==3){
setDirection(Location.SOUTH);
}
if(canMove() && strokeNum<4){
move();
steps++;
if(steps>=lineLength){
steps=0;
strokeNum++;
}
}
}
}
import info.gridworld.actor.Bug;
导入info.gridworld.grid.Location;
公共类MBug扩展Bug{
专用整数线长度;
私有int步骤;
/*strokeNum基本上是一个告诉bug它在哪个笔划上的代码。
*在这种情况下,“M”有四个笔划:
*向上,向下,向上,然后向下。
*此方法可用于创建任何字母,
*但是圆形笔划(C、R等)需要太多的单独笔划,这几乎是不可能的。
*/
斯特罗肯努姆私人酒店;
公共MBug(整数长度){
lineLength=长度;
步长=0;
锶=0;
}
公共无效法案({
如果(strokeNum==0){
设置方向(位置:北);
}否则如果(strokeNum==1){
设置方向(位置东南);
//这是为了缩短此笔划的长度。
steps++;
}否则如果(strokeNum==2){
设置方向(位置:东北);
//这是为了缩短此笔划的长度。
steps++;
}否则如果(strokeNum==3){
设置方向(位置:南);
}
if(canMove()&&strokeNum=lineLength){
步长=0;
锶++;
}
}
}
}