DicesList eingeführt
Diese neue abstrakte Klasse generiert eine Liste von Würfeln, welche hintereinander dargestellt werden. Die Unterklassen DefenderDices & OffenderDices passen jeweils nur noch die Farbe der Würfel an. Entsprechende Einträge in die Architektur folgen.master
parent
8ab61027ce
commit
1ee7463a33
@ -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));
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue