finished uebung10
This commit is contained in:
parent
b439030fee
commit
9908656813
BIN
bin/uebung10/logo/HanselGretelTest.class
Normal file
BIN
bin/uebung10/logo/HanselGretelTest.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelVisitor$1.class
Normal file
BIN
bin/uebung10/logo/HanselGretelVisitor$1.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30
src/uebung10/logo/HanselGretelTest.java
Normal file
30
src/uebung10/logo/HanselGretelTest.java
Normal file
@ -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<Void> visitor = new HanselGretelVisitor(10, turtle, new BlackForest()); //final ist egal
|
||||
PROG.accept(visitor);
|
||||
assertEquals(2, turtle.getX(), EPS);
|
||||
assertEquals(1, turtle.getY(), EPS);
|
||||
}
|
||||
|
||||
}
|
@ -46,6 +46,15 @@ public class HanselGretelVisitor implements Visitor<Void> {
|
||||
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<Void> {
|
||||
|
||||
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(){}
|
||||
|
Loading…
Reference in New Issue
Block a user