![]() |
#2
Beta012016-02-13 14:47
|


import stanford.karel.*;
public class StoneMasonKarel extends SuperKarel {
public void run() {
turnLeft();
turnrightAnd4Steps();
putdownAndMove();
moveOnly();
}
/*Turn right and move 4 steps while the front is blocked*/
private void turnrightAnd4Steps() {
if (frontIsBlocked()) {
turnRight();
for (int i=0; i<4; i++){
move();
}
turnRight();
} else {
putdownAndMove();
moveOnly();
}
}
/*Put beeper and move while there is no beeper*/
private void putdownAndMove() {
while (noBeepersPresent()) {
putBeeper();
move();
}
}
/*Just move while there is a beeper*/
private void moveOnly() {
while (beepersPresent()) {
move();
}
}
}
public class StoneMasonKarel extends SuperKarel {
public void run() {
turnLeft();
turnrightAnd4Steps();
putdownAndMove();
moveOnly();
}
/*Turn right and move 4 steps while the front is blocked*/
private void turnrightAnd4Steps() {
if (frontIsBlocked()) {
turnRight();
for (int i=0; i<4; i++){
move();
}
turnRight();
} else {
putdownAndMove();
moveOnly();
}
}
/*Put beeper and move while there is no beeper*/
private void putdownAndMove() {
while (noBeepersPresent()) {
putBeeper();
move();
}
}
/*Just move while there is a beeper*/
private void moveOnly() {
while (beepersPresent()) {
move();
}
}
}
类似这样的情况在设计其他情景时也出现 if else 没有执行, 是否有可能是软件中没有能执行这个命令的功能? 初学菜鸟请教各位大师

[此贴子已经被作者于2016-2-12 22:37编辑过]