在Karel中点练习(Java)中使用getter和setter
我写这段代码是为了使用比本课程预期的更多的Java元素。但是我很难让它在四个方向上都工作。getter和setter嵌入到使Karel移动的方法中。如果我能得到任何帮助,使这个鳕鱼工作,那将是伟大的
import stanford.karel.*;
public class MidpointFindingKarel extends SuperKarel {
public void run(){
while(facingEast()){
moveEast();
}
while(facingNorth()){
moveNorth();
}
while(facingWest()){
moveWest(moveEast());
}
while(facingSouth()){
moveSouth(moveNorth());
}
}
private int moveEast(){
int width = 0;
while(frontIsClear()){
width++;
move();
}
turnLeft();
width /= 2;
return width;
}
private int moveNorth(){
int height = 0;
while(frontIsClear()){
height++;
move();
}
turnLeft();
height /= 2;
return height;
}
private void moveWest(int _width){
for(int _w = 0; _w < _width; _w++){
move();
}
turnLeft();
}
private void moveSouth(int _height){
for(int _h = 0; _h < _height; _h++){
move();
}
turnLeft();
}
}
# 1 楼答案
请你具体说明一下,你的代码应该做什么? 如果你想做的就是在每面墙的中点放一个传呼机,我会做一个单独的方法。 如果我的解决方案不能回答您的问题,请提前道歉