From 1ee7463a33a0ec3c24d70f3a72af7d4407c6dbab Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Tue, 14 Jun 2016 09:00:54 +0200 Subject: [PATCH] =?UTF-8?q?DicesList=20eingef=C3=BChrt=20Diese=20neue=20ab?= =?UTF-8?q?strakte=20Klasse=20generiert=20eine=20Liste=20von=20W=C3=BCrfel?= =?UTF-8?q?n,=20welche=20hintereinander=20dargestellt=20werden.=20Die=20Un?= =?UTF-8?q?terklassen=20DefenderDices=20&=20OffenderDices=20passen=20jewei?= =?UTF-8?q?ls=20nur=20noch=20die=20Farbe=20der=20W=C3=BCrfel=20an.=20Entsp?= =?UTF-8?q?rechende=20Eintr=C3=A4ge=20in=20die=20Architektur=20folgen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DefenderDices.java | 16 +++++++++++++ DicesList.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++ OffenderDices.java | 16 +++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 DefenderDices.java create mode 100644 DicesList.java create mode 100644 OffenderDices.java diff --git a/DefenderDices.java b/DefenderDices.java new file mode 100644 index 0000000..d4fd927 --- /dev/null +++ b/DefenderDices.java @@ -0,0 +1,16 @@ +import greenfoot.*; +import java.util.Arrays; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + Erstellt eine gegebene Anzahl an DefenderDice's, welche dann nebeneinander eingereiht werden. + + @author Felix Stupp + @version 14.06.2016 +*/ +public class DefenderDices extends DicesList { + + public DefenderDices(int count) { + genDices(count, 2, new Color(0,0,0), (new Color(255,255,255)); + } + +} diff --git a/DicesList.java b/DicesList.java new file mode 100644 index 0000000..cb0fdfa --- /dev/null +++ b/DicesList.java @@ -0,0 +1,60 @@ +import greenfoot.*; +import java.awt.Color; +import java.util.Arrays; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + Erstellt eine gegebene Anzahl an Dices's, welche dann nebeneinander eingereiht werden. + + @author Felix Stupp + @version 14.06.2016 +*/ +public abstract class DicesList extends Actor { + + private final static int SQUARESIZE = 100; // Anpassbar + private Dice[] dices; + + public DicesList() { + setImage(new GreenfootImage(2,2)); + } + + protected void genDices(int count, int max, Color bC, Color fC) { + if(count < 1) { + count = 1; + } else if (count > max) { + count = max; + } + for(int i = 1; i < count; i++) { + Dice d = new Dice(); + d.setBackColor(bC); + d.setForeColor(fC); + d.setSizeAsSquare(SQUARESIZE); + dices[i] = d; + } + } + + protected void addedToWorld(World w) { + for(int i = 0; i < dices.length; i++) { + w.addObject(dices[i],w.getX()+(SQUARESIZE*(6/5)*i),w.getY()); + } + //w.removeObject(this); // Zeile auskommentieren, wenn die Debug-Phase vorbei ist. + } + + public int[] getNumbers() { + int[] n = new int[dices.length]; + for(int i = 0; i < dices.length; i++) { + n[i] = dices[i].getNumber(); + } + Arrays.sort(n); + return n; + } + + public int[] roll() { + int[] n = new int[dices.length]; + for(int i = 0; i < dices.length; i++) { + n[i] = dices[i].roll(); + } + Arrays.sort(n); + return n; + } + +} diff --git a/OffenderDices.java b/OffenderDices.java new file mode 100644 index 0000000..e2123d5 --- /dev/null +++ b/OffenderDices.java @@ -0,0 +1,16 @@ +import greenfoot.*; +import java.util.Arrays; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + Erstellt eine gegebene Anzahl an OffenderDice's, welche dann nebeneinander eingereiht werden. + + @author Felix Stupp + @version 14.06.2016 +*/ +public class OffenderDices extends DicesList { + + public OffenderDices(int count) { + genDices(count, 3, new Color(255,0,0), (new Color(255,255,255)); + } + +}