Public feed #726384

Someone

public java v1 · immutable
Raw Edit
·published 2007-10-05 04:00 UTC
rendered paste body
import javax.swing.*;/** * Creates turtles for the logo interpreter. * Tracks position and direction of the turtle and provides methods to move and rotate the turtle. */public class Turtle{	/** x coordinate of the turtle */	private int x;	/** y coordinate of the turtle */	private int y;	/** direction the turtle is facing, in radians */	private double direction;	/** name of the turtle */	private String name;	private String imagePath;	private ImageIcon turtleIcon;	/**	 * Constructs a new <code>Turtle</code>  using default values for x, y, direction, using x and y values of zero and a direction of 90 degrees, and a name of the turtle relating to the number in existance.	 *///	public Turtle(){//		this("Turtle" + count);	//}	/**	 * Constructs a new <code>Turtle</code> using default values for x, y, direction, but allows the name to be specified.	 * @param name The name of the new turtle object.	 */	public Turtle(String name){		//this(0,0,90,name,"turtle.png");		this(0,0,90,name);	}	public Turtle(String name, String imagePath){		//this(0,0,90,name,imagePath);		this(0,0,90,name);	}	/**	 * Constructs a new <code>Turtle</code> specifying an initial x,y position and direction.	 * @param x the initial x position of the turtle	 * @param y the initial y position of the turtle	 * @param direction the initial direction of the turtle, in degrees.	 */	public Turtle(int x, int y, double direction, String name){		this.x = x;		this.y = y;		this.direction = Math.toRadians(direction);		this.name = name;		//this.imagePath = imagePath;		//turtleIcon = new ImageIcon(this.imagePath);	}	/**	 * Gets the value of x.	 * @return the current x position	 */	public int getX(){		return x;	}	/**	 * Gets the value of y.	 * @return the current y position	 */	public int getY(){		return y;	}	/**	 * Gets the value of the direction.	 * @return the current direction, in radians	 */	public double getDirection(){		return direction;	}	/**	 * Gets the turtle's name	 * @return the turtle's name	 */	public String getName(){		return name;	}	/**	 * Gets the number of turtles.	 * @return the number of turtles	 */	//public int getCount(){	//	return count;	//}	/**	 * Gets the image path for the turtle.	 * @return the path to the turtle image	 */	public String getImagePath(){		return imagePath;	}	public ImageIcon getTurtleIcon(){		return turtleIcon;	}	/**	 * Sets the value of x.	 * @param x the new value of x	 */	public void setX(int x){		this.x = x;	}	/**	 * Sets the value of y.	 * @param y the new value of y	 */	public void setY(int y){		this.y = y;	}	/**	 * Sets the value of the direction.	 * @param direction the new value of the direction, in radians	 */	public void setDirection(double direction){		this.direction = direction;	}	/**	 * Sets the name of the turtle.	 * @param name the name of the turtle	 */	public void setName(String name){		this.name = name;	}	/**	 * Sets the image path of the turtle	 * @param imagePath the path to the image	 */	public void setImagePath(String imagePath){		this.imagePath = imagePath;	}	public void setTurtleIcon(ImageIcon turtleIcon){		this.turtleIcon = turtleIcon;	}	/**	 * Rotates the turtle.	 * @param angle the direction to rotate the turtle, in degrees	 */	public void rotate(int angle){		direction += Math.toRadians(angle);	}	/**	 * Moves the turtle.	 * Takes the distance and adds the x and y components to x and y	 * @param dist the total distance to move the turtle	 */	public void move(int dist){		x += (int)(dist*Math.cos(direction));		y += (int)(dist*Math.sin(direction));	}}