User Tools

Site Tools


steeplechaser

This is an old revision of the document!


SteepleChaser

 
public class SteepleChaser extends Robot
{
 
	public SteepleChaser(int street, int avenue, Direction direction, int beepers) 
	{
		super(street, avenue, direction, beepers);
	}
	public void jumpUp() 
	{
 
		while(! this.frontIsClear() ) 
		{
			turnLeft();
			move();
			turnRight();
		}
	}
	public void glideDown() 
	{
		turnRight();
		while (this.frontIsClear() )
			move();
		turnLeft();
 
	}
	public void runRace() 
	{
		for(int i = 0; i < 4; i++) 
		{
			jumpHurdle();
			while( this.frontIsClear() ) 
			{
				move();
			}
		}
		jumpHurdle();
	}
}

SteepleChaserRunner.java

import kareltherobot.Directions;
import kareltherobot.World;
 
public class SteepleChaseRunner implements Directions{
 
	public static void main(String[] args) {
		String steeples = "streets 8\n" + 
				"avenues 15\n" + 
				"northsouthwalls 4 3 3\n" + 
				"northsouthwalls 8 2 2\n" + 
				"northsouthwalls 6 2 2\n" + 
				"northsouthwalls 4 2 2\n" + 
				"northsouthwalls 1 2 2\n" + 
				"northsouthwalls 8 1 1\n" + 
				"northsouthwalls 6 1 1\n" + 
				"northsouthwalls 4 1 1\n" + 
				"northsouthwalls 2 1 1\n" + 
				"northsouthwalls 1 1 1";
		World.getWorld(steeples);
		World.setVisible();
		World.setDelay(10);
        task();
	}
 
	private static void task() {
		SteepleChaser horse = new SteepleChaser(1,1,East,0);
	    horse.runRace();
		horse.turnOff();
 
	}
 
}
steeplechaser.1566937595.txt.gz · Last modified: 2019/08/27 16:26 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki