From 17945a953de5c106587020808ba42d2b119c3cd2 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Mon, 17 Oct 2022 16:30:01 +0200 Subject: [PATCH] Solved Task 1 --- src/ch/zhaw/ads/ADS4_1_test.java | 3 +-- src/ch/zhaw/ads/SnowflakeServer.java | 30 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/ch/zhaw/ads/SnowflakeServer.java diff --git a/src/ch/zhaw/ads/ADS4_1_test.java b/src/ch/zhaw/ads/ADS4_1_test.java index c5a65bc..1dce82c 100644 --- a/src/ch/zhaw/ads/ADS4_1_test.java +++ b/src/ch/zhaw/ads/ADS4_1_test.java @@ -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 { } } } -*/ \ No newline at end of file diff --git a/src/ch/zhaw/ads/SnowflakeServer.java b/src/ch/zhaw/ads/SnowflakeServer.java new file mode 100644 index 0000000..9e8a4cb --- /dev/null +++ b/src/ch/zhaw/ads/SnowflakeServer.java @@ -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); + } + } +}