学到更多

参考


本附录在单个页面上定义了Karel编程语言的结构。

Base Karel承诺:

move();
turnLeft();
putBeeper();
pickBeeper();

卡雷尔计划结构:

/* 评论可以包含在任何部分中
 * 的 a 程序. 他们 开始 同 a 削减-星
 * and end with a star-slash.
 */
public class 名称 extends 超级卡雷尔 {

   public void run() {
       要执行的代码
   }

    私有方法的声明
}

条件名称:
frontIsClear()
beepersPresent()
beepersInBag()
leftIsClear()
rightIsClear()
facingNorth()
facingSouth()
facingEast()
facingWest()
frontIsBlocked() noBeepersPresent()
noBeepersInBag()
leftIsBlocked()
rightIsBlocked()
notFacingNorth()
notFacingSouth()
notFacingEast()
notFacingWest()
条件:

if( 条件 ){
代码run如果条件通过
}

if( 条件 ){
代码块为“是”
} else {
代码块为“否”
}

循环:

for(int i = 0; i <  计数 ; i++){
代码重复
}

while( 条件 ){
代码重复
}

方法声明:

private void 名称 () {
代码在方法体中。
}

超级卡雷尔附加命令:

turnRight();
turnAround();
random( p );
paintCorner( 颜色 );