1)
Code import stanford.karel.Karel;
/** * */
/** * @author student *
*/ public class AngkorKarel extends Karel {
/** * @param args */ public void run() { claimUp(); longJump(); move(); claimDown();
}
public void claimUp() { for (int i = 0; i < 3; i++) { turnLeft(); move(); turnRight(); move(); } }
public void turnRight() { turnLeft(); turnLeft(); turnLeft(); }
public void longJump() { move(); turnAround(); turnAround(); move(); }
public void turnAround() { turnLeft(); turnLeft(); }
public void claimDown() { for (int i = 0; i < 3; i++) { turnRight();
move(); turnLeft(); move(); } }
} ขั้นตอนการทำางาน
2)
Code import stanford.karel.Karel;
/** * */
/** * @author student * */ public class CambodiaKarel extends Karel {
/** * @param args */
public void run() { while (frontIsClear()) { for (int i = 0; i < 3; i++) { move();
} highJump(); }
}
public void highJump() { turnLeft(); move(); turnRight(); move(); turnRight(); move(); turnLeft(); }
public void turnRight() {
turnLeft(); turnLeft(); turnLeft(); }
} ขั้นตอนการทำางาน
3)
Code import stanford.karel.Karel;
/** * */
/** * @author student * */ public class RabsaraKarel extends Karel {
/** * @param args */
public void run() { highJump(); move(); turnRight(); while (frontIsClear()) { move(); } turnLeft(); putBeeper(); highJump();
}
public void highJump() { for (int i = 0; i < 4; i++) { turnLeft(); move(); turnRight(); move(); } }
public void turnRight() { turnLeft(); turnLeft(); turnLeft(); }
} ขันตอนการทำางาน
4)
Code import stanford.karel.Karel;
/** * */
/** * @author student * */ public class BarayKarel extends Karel {
/** * @param args
*/ public void run() { for (int i = 0; i < 5; i++) { fillPothole(); }
}
public void fillPothole() { move(); turnRight(); move(); move(); putBeeper(); turnAround(); move(); move(); turnRight(); move(); }
public void turnRight() {
turnLeft(); turnLeft(); turnLeft(); }
public void turnAround() { turnLeft(); turnLeft(); }
} ขั้นตอนการทำางาน
5)
Code import stanford.karel.Karel;
/** * */
/** * @author student * */
public class SiharnuKarel extends Karel {
/** * @param args */ public void run() { for (int i = 0; i < 13; i++) { claimUp();
} move(); move(); pickBeeper();
}
public void claimUp() { move(); putBeeper(); turnAround(); move(); turnRight();
move(); turnRight();
}
public void turnRight() { turnLeft(); turnLeft(); turnLeft(); }
public void turnAround() { turnLeft(); turnLeft(); }
}