User Tools

Site Tools


steeplechaser

SteepleChaser

Designing and Writing methods

import kareltherobot.*;
 
/**
 * Homework
 *
 * @author (your name)
 * @version (a version number or a date)
 */
 
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.txt · Last modified: 2023/08/22 09:53 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki