Ich hasse Minas
This commit is contained in:
parent
7fea13b9b3
commit
b439030fee
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelVisitor$DownState.class
Normal file
BIN
bin/uebung10/logo/HanselGretelVisitor$DownState.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelVisitor$LongUpSate.class
Normal file
BIN
bin/uebung10/logo/HanselGretelVisitor$LongUpSate.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelVisitor$ShortUpState.class
Normal file
BIN
bin/uebung10/logo/HanselGretelVisitor$ShortUpState.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelVisitor$State.class
Normal file
BIN
bin/uebung10/logo/HanselGretelVisitor$State.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -7,9 +7,8 @@ public class Go implements Stmt{
|
||||
public Go(double dist) {
|
||||
if (dist < 0) {
|
||||
throw new IllegalArgumentException();
|
||||
} else {
|
||||
this.dist = dist;
|
||||
}
|
||||
this.dist = dist;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,11 +1,12 @@
|
||||
package uebung10.logo;
|
||||
|
||||
public class HanselGretelVisitor implements Visitor<Turtle> {
|
||||
public class HanselGretelVisitor implements Visitor<Void> {
|
||||
|
||||
private double gap;
|
||||
private double s;
|
||||
private Turtle turtle;
|
||||
private DarkForest forest;
|
||||
private State state;
|
||||
|
||||
public HanselGretelVisitor(double s, Turtle turtle, DarkForest forest) {
|
||||
this.s = s;
|
||||
@ -13,6 +14,76 @@ public class HanselGretelVisitor implements Visitor<Turtle> {
|
||||
this.forest = forest;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Void visit(PenUp penUp) {
|
||||
up();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(PenDown penDown) {
|
||||
down();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(Turn turn) {
|
||||
turtle.turn(turn.angle);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(Sequence sequence) {
|
||||
for(Stmt elem :sequence.seq) {
|
||||
elem.accept(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(Go go) {
|
||||
go(go.dist);
|
||||
return null;
|
||||
}
|
||||
|
||||
private abstract class State {
|
||||
abstract void go(double dist);
|
||||
void up() {}
|
||||
void down() {}
|
||||
}
|
||||
|
||||
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 class LongUpSate extends State{
|
||||
void go(double d) {}
|
||||
void up(){}
|
||||
void down(){}
|
||||
}
|
||||
|
||||
private class DownState extends State{
|
||||
void go(double d){}
|
||||
void up(){}
|
||||
void down(){}
|
||||
}
|
||||
|
||||
private class ShortUpState extends State {
|
||||
void go(double d){}
|
||||
void up(){}
|
||||
void down(){}
|
||||
}
|
||||
|
||||
|
||||
private void go(double d) {
|
||||
state.go(d);
|
||||
}
|
||||
|
||||
private void down() {
|
||||
state.down();
|
||||
}
|
||||
|
||||
private void up() {
|
||||
state.up();
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ public class Sequence implements Stmt {
|
||||
public final Stmt[] seq;
|
||||
|
||||
public Sequence(Stmt... seq) {
|
||||
this.seq = seq;
|
||||
this.seq = seq.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user