Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Activity4;
- import kareltherobot.*;
- /**
- * This program uses robots to construct a house using beepers
- * @param - none
- * @return - none
- */
- public class Activity4Main implements Directions{
- public static void main(String[] args) {
- World.readWorld("Lesson3World4.kwld");
- World.setVisible();
- World.setDelay(20);
- WallBuilder john = new WallBuilder(1, 2, North, -1);
- WallBuilder cal = new WallBuilder(1,10, North, -1);
- RoofBuilder jack = new RoofBuilder(5,1, North, -1);
- WindowBuilder bob = new WindowBuilder(5, 4, North, -1);
- WindowBuilder tom = new WindowBuilder(5, 7, North, -1);
- DoorBuilder michael = new DoorBuilder(1,5, North, -1);
- john.build(); //all robots build with respective overriding
- cal.build();
- jack.build();
- bob.build();
- tom.build();
- michael.build();
- }
- }
- -----------------------------------
- Different file
- -----------------------------------
- package Activity4;
- import kareltherobot.*;
- /**
- * Constructicon - parent class
- * @param - none
- * @return - none
- */
- public class Constructicon extends UrRobot {
- public Constructicon(int s, int a, Direction d, int b){
- super(s, a, d, b);
- }
- public void build(){
- turnOff(); //if the overriding is successful, the robot shouldn't turn off
- }
- /**
- * Allows the robot to instantaneously turn right
- * @param - none
- * @return - Void
- */
- public void turnRight(){
- int delay = World.delay();
- World.setDelay(0);
- turnLeft();
- turnLeft();
- World.setDelay(delay);
- turnLeft();
- }
- }
- -----------------------------------
- Different file
- -----------------------------------
- package Activity4;
- /**
- * Builds the door of the house
- */
- public class DoorBuilder extends Constructicon{
- public DoorBuilder(int s, int a, Direction d, int b){
- super(s, a, d, b);
- }
- /**
- * @Override build
- */
- public void build(){
- for (int out = 0; out < 3; out++){
- for (int in = 0; in < 2; in++){
- putBeeper();
- move();
- }
- turnRight();
- }
- }
- }
- -----------------------------------
- Different file
- -----------------------------------
- package Activity4;
- /**
- * Subclass of Constructicon
- * Builds the roof of the house
- */
- public class RoofBuilder extends Constructicon{
- public RoofBuilder(int s, int a, Direction d, int b){
- super(s, a, d, b);
- }
- /**
- * @Override build
- */
- public void build(){
- for(int x = 0; x < 5; x++){ //builds the left part of roof
- putBeeper();
- move();
- turnRight();
- move();
- turnLeft();
- }
- putBeeper();
- turnRight();
- for(int y = 0; y < 5; y++){ //builds the right part of roof
- move();
- turnRight();
- move();
- putBeeper();
- turnLeft();
- }
- }
- }
- -----------------------------------
- Different file
- -----------------------------------
- package Activity4;
- /**
- * builds the walls of the house
- */
- public class WallBuilder extends Constructicon{
- public WallBuilder(int s, int a, Direction d, int b){
- super(s, a, d, b);
- }
- /**
- * @Override build
- */
- public void build(){
- for(int x = 0; x < 5; x++){
- putBeeper();
- move();
- }
- }
- }
- -----------------------------------
- Different file
- -----------------------------------
- package Activity4;
- /**
- * builds the windows of the house
- */
- public class WindowBuilder extends Constructicon{
- public WindowBuilder(int s, int a, Direction d, int b){
- super(s, a, d, b);
- }
- /**
- * @Override build
- */
- public void build(){
- for(int i = 0; i < 4; i++){
- putBeeper();
- move();
- turnRight();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement