stairsweeper
This is an old revision of the document!
StairSweeper.java
import kareltherobot.Robot; public class StairSweeper extends Robot { public StairSweeper(int street, int avenue, Direction direction, int beepers) { super(street, avenue, direction, beepers); } public void climbStair() { turnLeft(); move(); turnRight(); move(); } private void turnRight() { turnLeft(); turnLeft(); this.turnLeft(); } }
StairSweeperRunner.java
import kareltherobot.Directions; import kareltherobot.World; public class StairSweeperRunner implements Directions { public static void main(String[] args) { String steps = "streets 10\n" + "avenues 10\n" + "beepers 4 4 1\n" + "beepers 3 3 1\n" + "beepers 2 2 1\n" + "eastwestwalls 3 4 4\n" + "eastwestwalls 1 2 2\n" + "eastwestwalls 2 3 3\n" + "northsouthwalls 4 3 3\n" + "northsouthwalls 4 2 2\n" + "northsouthwalls 4 1 1\n" + "northsouthwalls 3 3 3\n" + "northsouthwalls 2 2 2\n" + "northsouthwalls 1 1 1"; World.getWorld(steps); World.setVisible(); task(); } private static void task() { StairSweeper alexa = new StairSweeper(1,1, East, 0); alexa.climbStair(); alexa.pickBeeper(); alexa.turnOff(); } }
stairsweeper.1566567999.txt.gz · Last modified: 2019/08/23 09:46 by frchris