Assignment1_StoneMasonKarel

来源:互联网 发布:童年阴影知乎 编辑:程序博客网 时间:2024/05/01 06:51
/*
 * File: StoneMasonKarel.java
 * --------------------------
 * The StoneMasonKarel subclass as it appears here does nothing.
 * When you finish writing it, it should solve the "repair the quad"
 * problem from Assignment 1.  In addition to editing the program,
 * you should be sure to edit this comment so that it no longer
 * indicates that the program does nothing.
 */


import stanford.karel.*;


/*
 * Name: 
 * Section Leader: 
 */


public class StoneMasonKarel extends SuperKarel {
public void run() {
while (frontIsClear()) {
toUp();
toNextColumn();
toDown();
toNextColumn();
}
}


private void toUp() {
turnLeft();
judgeBeeper();
turnRight();
}


private void toNextColumn() {
for (int i = 0; i < 4; i++)
move();
}


private void toDown() {
turnRight();
judgeBeeper();
turnLeft();
}


private void judgeBeeper() {
while (frontIsClear()) {
if (noBeepersPresent())
putBeeper();
move();
}
}
}
原创粉丝点击