diff --git a/bin/uebung10/logo/HanselGretelTest.class b/bin/uebung10/logo/HanselGretelTest.class new file mode 100644 index 0000000..36adb1b Binary files /dev/null and b/bin/uebung10/logo/HanselGretelTest.class differ diff --git a/bin/uebung10/logo/HanselGretelVisitor$1.class b/bin/uebung10/logo/HanselGretelVisitor$1.class new file mode 100644 index 0000000..5daac03 Binary files /dev/null and b/bin/uebung10/logo/HanselGretelVisitor$1.class differ diff --git a/bin/uebung10/logo/HanselGretelVisitor$DownState.class b/bin/uebung10/logo/HanselGretelVisitor$DownState.class index c14b60a..23584b2 100644 Binary files a/bin/uebung10/logo/HanselGretelVisitor$DownState.class and b/bin/uebung10/logo/HanselGretelVisitor$DownState.class differ diff --git a/bin/uebung10/logo/HanselGretelVisitor$LongUpSate.class b/bin/uebung10/logo/HanselGretelVisitor$LongUpSate.class deleted file mode 100644 index 7127ca3..0000000 Binary files a/bin/uebung10/logo/HanselGretelVisitor$LongUpSate.class and /dev/null differ diff --git a/bin/uebung10/logo/HanselGretelVisitor$ShortUpState.class b/bin/uebung10/logo/HanselGretelVisitor$ShortUpState.class index c4c6307..ba642a7 100644 Binary files a/bin/uebung10/logo/HanselGretelVisitor$ShortUpState.class and b/bin/uebung10/logo/HanselGretelVisitor$ShortUpState.class differ diff --git a/bin/uebung10/logo/HanselGretelVisitor$State.class b/bin/uebung10/logo/HanselGretelVisitor$State.class index 2817f07..823ded1 100644 Binary files a/bin/uebung10/logo/HanselGretelVisitor$State.class and b/bin/uebung10/logo/HanselGretelVisitor$State.class differ diff --git a/bin/uebung10/logo/HanselGretelVisitor.class b/bin/uebung10/logo/HanselGretelVisitor.class index 5484ad8..5a1d894 100644 Binary files a/bin/uebung10/logo/HanselGretelVisitor.class and b/bin/uebung10/logo/HanselGretelVisitor.class differ diff --git a/src/uebung10/logo/HanselGretelTest.java b/src/uebung10/logo/HanselGretelTest.java new file mode 100644 index 0000000..d68d8a9 --- /dev/null +++ b/src/uebung10/logo/HanselGretelTest.java @@ -0,0 +1,30 @@ +package uebung10.logo; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; + +public class HanselGretelTest { + + public static final double EPS = 1e-10; + public static final Stmt PROG = new Sequence(new PenDown(), new Go(50), + new Turn(120), new Go(50), + new Turn(120), new Go(50)); + + private Turtle turtle; + + @Before + public void setup() { + turtle = new Turtle(2, 1, 0); + } + + @Test + public void TestTriangle() { + final Visitor visitor = new HanselGretelVisitor(10, turtle, new BlackForest()); //final ist egal + PROG.accept(visitor); + assertEquals(2, turtle.getX(), EPS); + assertEquals(1, turtle.getY(), EPS); + } + +} diff --git a/src/uebung10/logo/HanselGretelVisitor.java b/src/uebung10/logo/HanselGretelVisitor.java index da1a7f0..8fe1f5c 100644 --- a/src/uebung10/logo/HanselGretelVisitor.java +++ b/src/uebung10/logo/HanselGretelVisitor.java @@ -46,6 +46,15 @@ public class HanselGretelVisitor implements Visitor { return null; } + private void breadCrumb() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'breadCrumb'"); + } + + private void layTrail(double d) { + forest.breadCrumb(turtle.getX(), turtle.getY()); + } + private abstract class State { abstract void go(double dist); void up() {} @@ -54,20 +63,28 @@ public class HanselGretelVisitor implements Visitor { private final State shortUp = new ShortUpState();// muss nicht geschrieben werden private final State down = new DownState();// muss nicht geschrieben werden - private final State longUp = new LongUpSate(); + private final State longUp = new State(){ - private class LongUpSate extends State{ - void go(double d) {} - void up(){} - void down(){} - } + @Override + void go(double d) {turtle.go(d);} + + @Override + void down(){ + breadCrumb(); + state = down; + } + + }; private class DownState extends State{ - void go(double d){} - void up(){} - void down(){} + void go(double d){ + layTrail(d); + } + + void up(){state = shortUp;} } + //TODO private class ShortUpState extends State { void go(double d){} void up(){}