package ch.nuth.zhaw.exbox; public class Turtle { private static StringBuffer b; private static double x, y; private static double angle; private static Turtle theTurtle; public static Turtle instance() { if (theTurtle == null) { theTurtle = new Turtle(); } return theTurtle; } public Turtle() { this(0, 0); } public Turtle(double x, double y) { reset(x, y); theTurtle = this; } public void reset(double x, double y) { b = new StringBuffer(); Turtle.x = x; Turtle.y = y; angle = 0; } public void clear() { reset(0, 0); } public String getTrace() { return b.toString(); } private double round(double d) { return Math.round(d * 10000) / 10000.0; } public void move(double dist) { b.append("\n"); } public void turn(double turnAngle) { angle += turnAngle * Math.PI / 180; } }