Solved Task 1
This commit is contained in:
parent
d5fabaf522
commit
17945a953d
|
@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test;
|
|||
import java.util.StringTokenizer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
/*
|
||||
|
||||
public class ADS4_1_test {
|
||||
SnowflakeServer sf;
|
||||
Turtle turtle;
|
||||
|
@ -98,4 +98,3 @@ public class ADS4_1_test {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -0,0 +1,30 @@
|
|||
package ch.zhaw.ads;
|
||||
|
||||
public class SnowflakeServer implements CommandExecutor {
|
||||
double distanz = 1.0;
|
||||
Turtle turtle;
|
||||
|
||||
@Override
|
||||
public String execute(String command) {
|
||||
turtle = new Turtle();
|
||||
int steps = Integer.parseInt(command);
|
||||
drawSnowFlake(steps, distanz);
|
||||
return turtle.getTrace();
|
||||
}
|
||||
|
||||
public void drawSnowFlake(int steps, double distanz){
|
||||
if(steps == 0) {
|
||||
turtle.move(distanz);
|
||||
} else {
|
||||
distanz = distanz / 3;
|
||||
steps--;
|
||||
drawSnowFlake(steps, distanz);
|
||||
turtle.turn(60);
|
||||
drawSnowFlake(steps, distanz);
|
||||
turtle.turn(-120);
|
||||
drawSnowFlake(steps, distanz);
|
||||
turtle.turn(60);
|
||||
drawSnowFlake(steps, distanz);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue