Merge pull request #74 from HGE-IT-Course-2016/Spielerauswahl-Extend

Spielerauswahl Erweitert
master
Felix Stupp 8 years ago committed by GitHub
commit 106aa944ab

@ -1,5 +1,6 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.awt.Graphics2D;
/**
Diese Klasse stellt einen Button dar.
@ -149,17 +150,12 @@ public class Button extends GUI_Interface {
sy = tI.getHeight() + (6 * 2) + 4;
}
GreenfootImage all = new GreenfootImage(sx,sy);
Color gray = new Color(133,133,133,255);
Color black = new Color(0,0,0,255);
Color trans = new Color(0,0,0,0);
Utils.drawInsideRectangle(all,gray,0);
Utils.drawInsideRectangle(all,black,2);
Utils.drawInsideRectangle(all,gray,6);
Utils.drawInsideRectangle(all,black,7);
all.setColorAt(0,0,trans);
all.setColorAt(sx-1,0,trans);
all.setColorAt(0,sy-1,trans);
all.setColorAt(sx-1,sy-1,trans);
all.setColor(trans);
all.fill();
Graphics2D g = all.getAwtImage().createGraphics();
g.setColor(backC);
g.fillRoundRect(0,0,sx,sy,24,24);
all.drawImage(tI,(sx-tI.getWidth())/2,(sy-tI.getHeight())/2);
setImage(all);
}

@ -1,4 +1,6 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import javax.swing.JOptionPane;
/**
* Write a description of class Colors here.
@ -15,46 +17,76 @@ public class Colours extends World implements ButtonEvent
Button lila = new Button ("Lila", 16, this);
Button gelb = new Button ("Gelb", 16, this);
Button weiter = new Button ("Weiter", 16, this);
int [] color = new int [6];
String [] pn = new String [6];
int[] color = new int [6];
String[] pn = new String [6];
int x = 0;
boolean possw = true;
boolean posbl = true;
boolean posgr = true;
boolean posrt = true;
boolean posgb = true;
boolean posli = true;
boolean possw = true; // schwarz
boolean posbl = true; // blau
boolean posgr = true; // gruen
boolean posrt = true; // rot
boolean posgb = true; // gelb
boolean posli = true; // lila
int sw = 1;
int bl = 2;
int gr = 3;
int rt = 4;
int gb = 5;
int li = 6;
Label header = new Label("Klicke auf eine Farbe, um einen Spieler hinzuzufügen:",16);
Button remove = new Button("Rückgängig",16,this);
Label pl1 = new Label("",16);
Label pl2 = new Label("",16);
Label pl3 = new Label("",16);
Label pl4 = new Label("",16);
Label pl5 = new Label("",16);
Label pl6 = new Label("",16);
/**
* Constructor for objects of class Colors.
*
*/
public Colours(int x, int y, int z)
{
super(x, y, z);
{
super(x, y, z);
setBackground(Start_Load.backgroundImage);
addObject(schwarz, 50, 30);
addObject ( blau, 170, 30);
addObject ( grün, 280, 30);
addObject ( rot, 390, 30);
addObject(gelb, 500, 30);
addObject(lila, 610, 30);
addObject (weiter, 335,90);
schwarz.setSize(100, 50);
gelb.setSize(100, 50);
blau.setSize(100, 50);
grün.setSize(100, 50);
rot.setSize(100, 50);
lila.setSize(100, 50);
weiter.setSize(100, 50);
Button[] bList = new Button[] {schwarz,gelb,blau,grün,rot,lila,weiter,remove};
Label[] lList = new Label[] {header,pl1,pl2,pl3,pl4,pl5,pl6};
addObject(header,200,15);
addObject(schwarz, 70, 50);
addObject ( blau, 190, 50);
addObject ( grün, 300, 50);
addObject ( rot, 410, 50);
addObject(gelb, 520, 50);
addObject(lila, 630, 50);
addObject(remove,300,110);
addObject (weiter, 410,110);
addObject(pl1,355,160);
addObject(pl2,355,180);
addObject(pl3,355,200);
addObject(pl4,355,220);
addObject(pl5,355,240);
addObject(pl6,355,260);
schwarz.setForeColor(Color.black);
gelb.setForeColor(Color.yellow);
blau.setForeColor(Color.blue);
grün.setForeColor(Color.green);
rot.setForeColor(Color.red);
lila.setForeColor(new Color(161,70,255));
for(int i = 0; i < bList.length; i++) {
bList[i].setSize(100,50);
}
for(int i = 0; i < lList.length; i++) {
lList[i].setBackColor(new Color(0,0,0,0));
}
redraw();
}
// Überprüft, ob ein Farbbutton geklickt wurde
//Überprüft, ob die Farbe noch nicht ausgewählt wurde
@ -69,52 +101,69 @@ public class Colours extends World implements ButtonEvent
if ( b == schwarz && possw == true)
{
color[x] = sw;
pn[x]="Schwarz";
x+=1;
possw = false;
pn[x]=getName(x,"Schwarz");
if(pn[x].length() > 0) {
x+=1;
possw = false;
}
}
if (b == blau && posbl == true)
{
color[x] = bl;
pn[x] = "Blau";
x+=1;
posbl = false;
pn[x]=getName(x,"Blau");
if(pn[x].length() > 0) {
x+=1;
posbl = false;
}
}
if (b == grün && posgr == true )
{
color[x] = gr;
pn[x]="Grün";
x+=1;
posgr = false;
pn[x]=getName(x,"Grün");
if(pn[x].length() > 0) {
x+=1;
posgr = false;
}
}
if ( b == rot && posrt == true)
{
color[x] = rt;
pn[x]="Rot";
x+=1;
posrt = false;
pn[x]=getName(x,"Rot");
if(pn[x].length() > 0) {
x+=1;
posrt = false;
}
}
if ( b == gelb && posgb == true)
{
color [x] = gb;
pn[x]="Gelb";
x+=1;
posgb = false;
pn[x]=getName(x,"Gelb");
if(pn[x].length() > 0) {
x+=1;
posgb = false;
}
}
if ( b == lila && posli == true)
{
color [x] = li;
pn[x]="Lila";
x+=1;
posli = false;
pn[x]=getName(x,"Lila");
if(pn[x].length() > 0) {
x+=1;
posli = false;
}
}
if ( b == weiter && x >=2 )
if(b == remove && x > 0) {
x -= 1;
switch(color[x]) {
case 1: possw = true; break;
case 2: posbl = true; break;
case 3: posgr = true; break;
case 4: posrt = true; break;
case 5: posgb = true; break;
case 6: posli = true; break;
}
}
if ( b == weiter && x > 2 )
{
String[] newpn = new String[x];
int[] newcolor = new int[x];
@ -122,13 +171,56 @@ public class Colours extends World implements ButtonEvent
{
newpn[i] = pn[i];
newcolor[i] = color[i];
}
World m = new Map(newcolor,x,newpn);
Greenfoot.setWorld(m);
}
redraw();
}
private Color getC(boolean pos) {
return (pos) ? Color.lightGray : Color.gray;
}
/**
Passt alle adaptiven Parameter automatisch an.
*/
private void redraw() {
schwarz.setBackColor(getC(possw));
blau.setBackColor(getC(posbl));
grün.setBackColor(getC(posgr));
rot.setBackColor(getC(posrt));
lila.setBackColor(getC(posli));
gelb.setBackColor(getC(posgb));
remove.setBackColor((x > 0) ? Color.black : Color.gray);
pl1.setText("");
pl2.setText("");
pl3.setText("");
pl4.setText("");
pl5.setText("");
pl6.setText("");
switch(x) {
case 6:
pl6.setText(pn[5]);
case 5:
pl5.setText(pn[4]);
case 4:
pl4.setText(pn[3]);
case 3:
pl3.setText(pn[2]);
case 2:
pl2.setText(pn[1]);
case 1:
pl1.setText(pn[0]);
}
}
private String getName(int id, String col) {
String name = JOptionPane.showInputDialog(null, "Wie soll Spieler Nr. "+id+" mit der Farbe "+col+" heißen?");
if(name == null) {
name = "";
}
return name;
}
}

@ -90,6 +90,11 @@ public class Label extends GUI_Interface {
*/
public void redraw() {
GreenfootImage tI = new GreenfootImage(text,textSize,foreC,backC);
if(text == "") {
tI = new GreenfootImage(1,1);
tI.setColor(new Color(0,0,0,0));
tI.fill();
}
if(autoSize) {
sx = tI.getWidth();
sy = tI.getHeight();

Loading…
Cancel
Save