Merge remote-tracking branch 'refs/remotes/origin/master' into Fehlerkorrekturen-by-SR

master
Zocker1999NET 8 years ago
commit b39e680aa1

@ -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,45 +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);
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);
{
super(x, y, z);
setBackground(Start_Load.backgroundImage);
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
@ -68,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];
@ -121,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;
}
}

@ -531,7 +531,7 @@ public abstract class GeneralMap extends World implements ButtonEvent
public int[] getProvinceOwners()
{
int[] prOwners = new int[provinces.length];
for (int i = 1; i > provinces.length; i++) {
for (int i = 1; i < provinces.length; i++) {
prOwners[i] = provinces[i].getOwner();
}
return prOwners;

@ -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();

@ -23,6 +23,7 @@ public class Map extends World implements ButtonEvent
public Map( int[] bunt, int zahl , String [] name)
{
super (1600,900,1);
setBackground(Start_Load.backgroundImage);
colour = new int[zahl];
pn = new String[zahl];
for (int i=0; i<zahl; i++)

@ -17,10 +17,7 @@ public class Player extends Actor
int id=0;
int provZahl=0;
int provVgl=0;
int [] stats = new int [6];
boolean [] pBesitzer = new boolean [42];
boolean gotProv = false;
boolean lostProv = false;
int[] stats = new int [6];
String n;
int color;
int textsize;
@ -45,14 +42,16 @@ public class Player extends Actor
return n;
}
//gibt die Sternenanzahl zurück
public int getStars ()
public int getStars()
{
return stars;
}
// erhöht die Sternenzahl um eine random ausgewählte Anzahl von 1-3
public void addToStars ()
{
// Von Felix: Methode nicht architektur-konform
/* // erhöht die Sternenzahl um eine random ausgewählte Anzahl von 1-3
public void addToStars()
{
int rand;
int pre;
rand = (int)(1+6*Math.random());
@ -80,56 +79,55 @@ public class Player extends Actor
System.out.println("Deine aktuelle Sternenanzahl beträgt " + stars + ".");
redrawPlayer();
}
} */
private void checkStars() {
if(stars < 0) {
stars = 0;
}
}
//eine Methode um addToStars zu testen
public void add ()
{
addToStars();
// Von Felix: Architektur-konforme Funktion
public int addToStars(int s) {
stars += s;
checkStars();
redrawPlayer();
return stars;
}
//eine für das Testen gedachte Methode, die die Anzahl der Sterne auf ein gewünschtes Maß setzt
public int setStars (int set)
{
stars = set;
checkStars();
redrawPlayer();
return stars;
}
//eine Methode, die das Abziehen von Sternen testet und, wenn das Ergebnis >= 0 ist, die Sternenanzahl um eine gewählte Anzahl verringert
public int removeFromStars(int sub)
{
int s;
s = stars - sub;
if (s>=0)
{
stars = s;
}
else
{
System.out.println ("Du hast nur " + stars + " Sterne, du kannst also nicht " + sub + " Sterne abziehen");
}
stars -= sub;
checkStars();
redrawPlayer();
return stars;
}
public boolean canStarsRemoved(int s) {
return (stars - s) >= 0;
}
public int getProvinceCount ()
public int getProvinceCount()
{
GeneralMap w= getWorld();
// int[] provinces = w.getProvinceOwners();
for (int x=1; x<=42; x++ )
int p = 0;
int[] provinces = getWorld().getProvinceOwners();
for (int x=1; x < provinces.length; x++)
{
c = w.provinces[x].getOwner();
if (c ==id+1)
if (provinces[x] == id)
{
provZahl++;
stats[2] = provZahl;
p++;
redrawPlayer();
}
}
return provZahl;
return p;
}
public void gotEntities(int gotEnt)
@ -140,7 +138,6 @@ public class Player extends Actor
public void lostEntity()
{
stats[4]+=1;
redrawPlayer();
}
@ -156,58 +153,22 @@ public class Player extends Actor
public boolean[] getMyProvinces()
{
GeneralMap w= getWorld();
int[] provinces = w.getProvinceOwners();
for (int x=0; x<=42; x++)
int[] provinces = getWorld().getProvinceOwners();
boolean[] myProvinces = new boolean[provinces.length];
for (int x=0; x < provinces.length; x++)
{
if (provinces[x]== id)
{
pBesitzer[x]=true;
myProvinces[x]=true;
}
else
{
pBesitzer[x]=false;
myProvinces[x]=false;
}
}
redrawPlayer();
return pBesitzer;
}
private void gotlostProvince()
{
if (provVgl== provZahl)
{
gotProv = false;
lostProv =false;
}
if(provVgl< provZahl)
{
gotProv = true;
lostProv = false;
stats[0]+=1;
}
if (provVgl > provZahl)
{
gotProv = false;
lostProv = true;
stats[1]+=1;
}
redrawPlayer();
provVgl = provZahl;
}
public boolean getGotProvince ()
{
redrawPlayer();
return gotProv;
}
public boolean getLostProvince()
{
redrawPlayer();
return lostProv;
return myProvinces;
}
public int[] getStatistics()

@ -8,7 +8,11 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
*/
public class Start_Load extends World implements ButtonEvent
{
Button chulien = new Button("Neues Spiel", 16 , this);
static String backgroundImage = "backgroundLight.png"; // Gibt an, welches Bild in allen Menüs als Hintergrund gewählt werden soll.
// Light Theme: "backgroundLight.png"
// Dark Theme: "backgroundDark.png"
Button chulien = new Button("Neues Spiel", 16 , this);
/**
* Constructor for objects of class Start_Load.
@ -18,24 +22,25 @@ public class Start_Load extends World implements ButtonEvent
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1600, 900, 1);
setBackground(backgroundImage);
chulien.setSize(100,50);
addObject (chulien, (1600-chulien.getWidth())/2, (900-chulien.getHeight())/2);
}
public void buttonClicked ( Button b)
{
if ( b == chulien)
{
World chean = new Colours (1600, 900, 1);
Greenfoot.setWorld(chean);
}
}
public void Load()
{
}
}
public void buttonClicked ( Button b)
{
if ( b == chulien)
{
World chean = new Colours (1600, 900, 1);
Greenfoot.setWorld(chean);
}
}
public void Load()
{
}
}

Before

Width:  |  Height:  |  Size: 953 KiB

After

Width:  |  Height:  |  Size: 953 KiB

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

Loading…
Cancel
Save