NEWS: Total Picture Views: 155283 | Total Article Views: 165628 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. PickUpThings with Becker Robot | 3. How to read a JSON and work with it | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

Creating a tree with Becker Robot [Updated Version] Java

Description:

Creating a tree with Becker Robot with different color of things. This is a new version updated.

Code:

/********************************** TestTree.java *************************************/
/**
 * @TestTree.java
 *
 *
 * @Jean-Mathieu Emond
 * @version 1.04 2013/12/3
 */
import becker.robots.*;

public class TestTree {
	public static void main (String[] args) {
		City city = new City(15,12);
		Tree aRobot = new Tree(city,14,4,Direction.EAST);
		Thing things = new Thing(aRobot);
	
									
		aRobot.loc1(aRobot);
		
		
		aRobot.loc2(aRobot);
		

		aRobot.loc3(aRobot);
		

		aRobot.loc4(aRobot);
		

		aRobot.loc5(aRobot);
		

		aRobot.loc6(aRobot);


		aRobot.loc7(aRobot);

	}
}
/********************************** Tree.java *************************************/
/**
 * @Tree.java
 *
 *
 * @Jean-Mathieu Emond
 * @version 1.04 2013/12/3
 */
import becker.robots.*;
import java.awt.Color;

public class Tree extends RobotSE {
	public Tree(City c, int st, int ave, Direction d){
		super(c, st, ave, d,100);
	
	}
	public void createBox(int x, int y,Robot aRobot,int steps){
	
		boolean dir = true;
		
		
		System.out.println("Size: " + x +" * " + y);
		System.out.println("We are at box " + steps + " / 7
");
		for (int i=1; i<y+1 ;i++) {
	         for (int s=1; s<x+1; s++) {
	         	Thing things = new Thing(aRobot);
	         	if (steps == 1) {
	         		Color brown = new Color(155,100,0);
	         		things.setColor(brown);
	         	}
	         	else if (steps > 1 && steps < 7)
	         	{
	         		things.setColor(Color.GREEN);
	         	}
	         			
	         	this.putThing();
	         	this.move();
	         	
	         }
	         if (dir == true) {
	         	this.turnLeft();
        		this.move();
        		this.turnLeft(); 
        		this.move();
        		dir=false;
	         }
	         else {
	         	this.turnRight();
	         	this.move();
	         	this.turnRight();
	         	this.move();
	         	dir=true;	
	         }
	 	}
	}

	public void loc1 (Robot aRobot) {
		int steps = 1;
		this.gotoLocation(14,4,1);
		this.faceDirection(Direction.EAST);
		this.createBox(3,3,aRobot,steps);
	}
		
	public void loc2 (Robot aRobot) {
		int steps = 2;
		this.gotoLocation(11,1,2);
		this.faceDirection(Direction.EAST);
		this.createBox(9,3,aRobot,steps);
	}
		
	public void loc3 (Robot aRobot) {
		int steps = 3;
		this.gotoLocation(8,2,3);
		this.faceDirection(Direction.EAST);
		this.createBox(7,3,aRobot,steps);		
	}
		
	public void loc4 (Robot aRobot) {
		int steps = 4;
		this.gotoLocation(5,3,4);
		this.faceDirection(Direction.EAST);
		this.createBox(5,2,aRobot,steps);
	}
		
	public void loc5 (Robot aRobot) {
		int steps = 5;
		this.gotoLocation(3,4,5);
		this.faceDirection(Direction.EAST);
		this.createBox(3,2,aRobot,steps);
	}
		
	public void loc6 (Robot aRobot) {
		int steps = 6;
		this.gotoLocation(1,5,6);
		this.faceDirection(Direction.EAST);
		this.createBox(1,1,aRobot,steps);
	}
		
	public void loc7 (Robot aRobot) {
		int steps = 7;
		this.gotoLocation(0,5,7);
		this.faceDirection(Direction.EAST);
		this.createBox(1,1,aRobot,steps);
		System.out.println("The tree has beed completed!");
		this.faceDirection(Direction.NORTH);
	}
		
	public void gotoLocation(int y, int x,int z) {
				
		switch (z) {
			case 1 :
				this.gotoAvenue(x);
				this.gotoStreet(y);
				break;
					
			case 2 :
				this.gotoAvenue(x);
				this.gotoStreet(y);
				break;
				
			case 3 :
				this.gotoAvenue(x);
				this.gotoStreet(y);
				break;
						
			case 4 :
				this.gotoAvenue(x);
				this.gotoStreet(y);
				break;
				
			case 5 :
				this.gotoAvenue(x);
				this.gotoStreet(y);
				break;
						
			case 6 :
				this.gotoAvenue(x);
				this.gotoStreet(y);
				break;
						
			case 7 :
				this.gotoAvenue(x);
				this.gotoStreet(y);
				break;
					
			default : 
				System.out.println("There is an error try again.");
		
		}
		
	}
	 public void faceDirection(Direction dir) {
    	while(this.getDirection() != dir) {
       		this.turnRight();
		}
	}
	
	 private void gotoAvenue (int ave) {
    	if (this.getAvenue()< ave)
    		this.faceDirection(Direction.EAST);
    	else	
    		this.faceDirection(Direction.WEST);	
    	while (this.getAvenue()!=ave) {
    		this.move();
    	}
    }
    private void gotoStreet (int st) {
    	if (this.getStreet()< st)
    		this.faceDirection(Direction.SOUTH);
    	else
    		this.faceDirection(Direction.NORTH);		
    	while (this.getStreet()!=st) {
    		this.move();
    	}
    }
}
Attachments: None

Tags: Becker Robot Becker Robot Tree

Total Views: 1225

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 11/24/14 and updated on 12/09/14


affiliate_link

Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.