From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Schlange2.inc | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Schlange2.inc') 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 -- cgit v1.2.3