summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc')
-rw-r--r--Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc47
1 files changed, 47 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc b/Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc
new file mode 100644
index 0000000..d50e494
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc
@@ -0,0 +1,47 @@
+/* Schlange2.inc */
+
+public void run()
+{
+ //Schlange konstruieren
+ ColorRectangle cr;
+ int x = 100;
+ int y = 100;
+ for (int i=0; i < NUMELEMENTS; ++i) {
+ cr = new ColorRectangle();
+ cr.x = x;
+ cr.y = y;
+ cr.width = SIZERECT;
+ cr.height = SIZERECT;
+ x += SIZERECT;
+ cr.color = new Color(
+ i*(256/NUMELEMENTS),
+ 0,
+ 240-i*(256/NUMELEMENTS)
+ );
+ snake.addElement(cr);
+ }
+
+ //Löschelement anhängen
+ cr = new ColorRectangle();
+ cr.x = x;
+ cr.y = y;
+ cr.width = SIZERECT;
+ cr.height = SIZERECT;
+ cr.color = BGCOLOR;
+ snake.addElement(cr);
+
+ //Vorzugsrichtung festlegen
+ dx = -1;
+ dy = -1;
+
+ //Schlange laufen lassen
+ while (true) {
+ repaint();
+ try {
+ Thread.sleep(SLEEP);
+ } catch (InterruptedException e){
+ //nichts
+ }
+ moveSnake();
+ }
+} \ No newline at end of file