Merge pull request #64 from HGE-IT-Course-2016/ArmyPlacer

ArmyPlacer 1.0.0
master
Felix Stupp 8 years ago committed by GitHub
commit f558d9e841

@ -1,4 +1,5 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import javax.swing.JOptionPane;
/**
* Write a description of class ArmyPlacer here.
@ -8,11 +9,7 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
*/
public class ArmyPlacer extends Map_World
{
public int armiesToPlace;
public int armyMinimum;
int freeArmies = -1;
/**
* Constructor for objects of class ArmyPlacer.
@ -37,38 +34,141 @@ public class ArmyPlacer extends Map_World
// Grüßen
// ,
// GruenerWal
//
//
//
// I'll be back.
}
public int calculateArmies()
{
int armiesToPlace;
Province[] continentArray;
boolean continentChecked = false;
// 1. ArmyMinimum einbeziehen
armiesToPlace = armyMinimum;
// 2. Einheiten durch Provinzen einbeziehen
armiesToPlace = armiesToPlace + Math.round(players[currentPlayer].getProvinceCount() / 3);
return 0;
// 3. Einheiten durch Kontinente
// Kontinente durchgehen
for ( int i = 1; i < continentBoni.length; i++ )
{
continentArray = giveContinentArray(i);
// Provinzen des aktuellen Kontinents durchgehen
for ( int p = 1; p >= continentArray.length; p++ )
{
// Prüfen, ob eine Provinz NICHT dem aktuellen Spieler gehört
if ( continentArray[p].getOwner() != currentPlayer )
{
break;
}
// Wenn nicht, wird der Kontinent als gecheckt markiert
else
{
continentChecked = true;
}
}
if ( continentChecked == true )
{
armiesToPlace = armiesToPlace + continentBoni[i];
continentChecked = false;
}
}
// 4. Einheiten durch Sterne
if ( players[currentPlayer].getStars() > 0)
{
String toUseString = JOptionPane.showInputDialog(null, "Wieviele Sterne willst du verwenden?");
int starsToUse = Utils.StringToInt(toUseString);
int[] starBoni = new int [] {1,2,4,7,10,13,17,21,25,30};
if ( starsToUse > 0 && starsToUse < 11 )
{
armiesToPlace = armiesToPlace + starBoni[starsToUse -1];
}
if ( starsToUse < 0 && starsToUse > 10 )
{
JOptionPane.showMessageDialog(null,"Ungültige Zahl. Bitte eine Zahl zwischen 0 und 10 eingeben");
}
}
return armiesToPlace;
}
public Province[] giveContinentArray(int cID)
{
Province[] savedProvinces = new Province[provinceCount +1];
Province[] continentProvinces;
int c = 0;
for (int i = 1; i <= provinceCount; i++)
{
if (provinces[i].getContinentID() == cID)
{
savedProvinces[i] = provinces[i];
c++;
}
}
return Utils.cutArray(savedProvinces);
if ( c < 1 )
{
return null;
}
else
{
return Utils.cutArray(savedProvinces);
}
}
public void placeArmies()
{
if ( freeArmies == -1 )
{
freeArmies = calculateArmies();
}
for ( int i = 1; i <= (provinces.length - 1); i++) {
if (provinces[i].hasClicked() == true && provinces[i].getOwner() == currentPlayer)
{
String toUseString = JOptionPane.showInputDialog(null, "Wieviele Einheiten willst du setzen? Du hast noch " + freeArmies + " freie Einheiten.");
int armiesToUse = Utils.StringToInt(toUseString);
if ( armiesToUse <= freeArmies )
{
provinces[i].addToEntities(armiesToUse);
freeArmies = freeArmies- armiesToUse;
JOptionPane.showMessageDialog(null,"Einheiten erfolgreich gesetzt, Kommandant " + getPlayerName() + ".");
}
else if ( armiesToUse > freeArmies )
{
JOptionPane.showMessageDialog(null,"Nicht genügend freie Einheiten.");
}
}
}
}
public void act()
{
placeArmies();
}
}

@ -117,90 +117,90 @@ public abstract class GeneralMap extends World implements ButtonEvent
Spieler 2 ist als zweites dran; Hauptstadt: 20
Spieler 3 ist als drittes dran und bekommt eine Karte; Hauptstadt: 9
*/
dataL = new int[] {1,1,3,2,2,2,2,1,1,1,1,1,3,2,1,1,3,4,3,1,2,2,1,2,1,2,3,3,3,3,3,3,1,1,2,2,2,4,2,3,1,1,3,4,1,2,3,4,2,2,2,1,3,1,1,3,1,3,1,4,3,1,2,1,2,1,1,2,2,2,3,1,2,2,2,4,2,3,1,4,3,1,1,2};
provinces[1].setOwner(1);
dataL = new int[] {0,1,2,2,1,2,1,1,0,1,0,1,2,2,0,1,2,4,2,1,1,2,0,2,0,2,2,3,2,3,2,3,0,1,1,2,1,4,1,3,0,1,2,4,0,2,2,4,1,2,1,1,2,1,0,3,0,3,0,4,2,1,1,1,1,1,0,2,1,2,2,1,1,2,1,4,1,3,0,4,2,1,0,2};
provinces[1].setOwner(0);
provinces[1].setEntityCount(1);
provinces[2].setOwner(3);
provinces[2].setOwner(2);
provinces[2].setEntityCount(2);
provinces[3].setOwner(2);
provinces[3].setOwner(1);
provinces[3].setEntityCount(2);
provinces[4].setOwner(2); //Fabrik
provinces[4].setOwner(1); //Fabrik
provinces[4].setEntityCount(1);
provinces[5].setOwner(1);//Fabrik
provinces[5].setOwner(0);//Fabrik
provinces[5].setEntityCount(1);
provinces[6].setOwner(1);//Fabrik
provinces[6].setOwner(0);//Fabrik
provinces[6].setEntityCount(1);
provinces[7].setOwner(3);
provinces[7].setOwner(2);
provinces[7].setEntityCount(2);
provinces[8].setOwner(1);
provinces[8].setOwner(0);
provinces[8].setEntityCount(1);
provinces[9].setOwner(3);
provinces[9].setOwner(2);
provinces[9].setEntityCount(4);
provinces[10].setOwner(3);
provinces[10].setOwner(2);
provinces[10].setEntityCount(1);
provinces[11].setOwner(2);//Fabrik
provinces[11].setOwner(1);//Fabrik
provinces[11].setEntityCount(2);
provinces[12].setOwner(1);
provinces[12].setOwner(0);
provinces[12].setEntityCount(2);
provinces[13].setOwner(1);//Fabrik
provinces[13].setOwner(0);//Fabrik
provinces[13].setEntityCount(2);
provinces[14].setOwner(3);//Fabrik
provinces[14].setOwner(2);//Fabrik
provinces[14].setEntityCount(3);
provinces[15].setOwner(3);//Fabrik
provinces[15].setOwner(2);//Fabrik
provinces[15].setEntityCount(3);
provinces[16].setOwner(3);//Fabrik
provinces[16].setOwner(2);//Fabrik
provinces[16].setEntityCount(3);
provinces[17].setOwner(1);
provinces[17].setOwner(0);
provinces[17].setEntityCount(1);
provinces[18].setOwner(2);
provinces[18].setOwner(1);
provinces[18].setEntityCount(2);
provinces[19].setOwner(2);//Fabrik
provinces[19].setOwner(1);//Fabrik
provinces[19].setEntityCount(4);
provinces[20].setOwner(2);
provinces[20].setOwner(1);
provinces[20].setEntityCount(3);
provinces[21].setOwner(1);
provinces[21].setOwner(0);
provinces[21].setEntityCount(1);
provinces[22].setOwner(3);//Fabrik
provinces[22].setOwner(2);//Fabrik
provinces[22].setEntityCount(4);
provinces[23].setOwner(1);
provinces[23].setOwner(0);
provinces[23].setEntityCount(2);
provinces[24].setOwner(3);
provinces[24].setOwner(2);
provinces[24].setEntityCount(4);
provinces[25].setOwner(2);
provinces[25].setOwner(1);
provinces[25].setEntityCount(2);
provinces[26].setOwner(2);//Fabrik
provinces[26].setOwner(1);//Fabrik
provinces[26].setEntityCount(1);
provinces[27].setOwner(3);
provinces[27].setOwner(2);
provinces[27].setEntityCount(1);
provinces[28].setOwner(1);//Fabrik
provinces[28].setOwner(0);//Fabrik
provinces[28].setEntityCount(3);
provinces[29].setOwner(1);//Fabrik
provinces[29].setOwner(0);//Fabrik
provinces[29].setEntityCount(3);
provinces[30].setOwner(1);
provinces[30].setOwner(0);
provinces[30].setEntityCount(4);
provinces[31].setOwner(3);
provinces[31].setOwner(2);
provinces[31].setEntityCount(1);
provinces[32].setOwner(2);
provinces[32].setOwner(1);
provinces[32].setEntityCount(1);
provinces[33].setOwner(2);
provinces[33].setOwner(1);
provinces[33].setEntityCount(1);
provinces[34].setOwner(1);
provinces[34].setOwner(0);
provinces[34].setEntityCount(2);
provinces[35].setOwner(2);
provinces[35].setOwner(1);
provinces[35].setEntityCount(2);
provinces[36].setOwner(3);
provinces[36].setOwner(2);
provinces[36].setEntityCount(1);
provinces[37].setOwner(2);
provinces[37].setOwner(1);
provinces[37].setEntityCount(2);
provinces[38].setOwner(2);//Fabrik
provinces[38].setOwner(1);//Fabrik
provinces[38].setEntityCount(4);
provinces[39].setOwner(2);
provinces[39].setOwner(1);
provinces[39].setEntityCount(3);
provinces[40].setOwner(1);
provinces[40].setOwner(0);
provinces[40].setEntityCount(4);
provinces[41].setOwner(3);//Fabrik
provinces[41].setOwner(2);//Fabrik
provinces[41].setEntityCount(1);
provinces[42].setOwner(1);
provinces[42].setOwner(0);
provinces[42].setEntityCount(2);
} else if(players.length==4) {
/*
@ -209,90 +209,90 @@ public abstract class GeneralMap extends World implements ButtonEvent
Spieler 3 ist als drittes dran und bekommt eine Karte; Hauptstadt:2
Spieler 4 ist als viertes dran und bekommt eine Karte; Hauptstadt:39
*/
dataL = new int[] {1,1,3,3,3,3,3,2,3,2,3,3,2,2,1,2,2,2,3,2,2,3,3,2,2,3,1,3,1,3,1,3,3,2,4,2,2,4,2,4,1,1,1,2,1,5,1,3,2,2,4,3,4,1,4,2,2,2,2,2,4,1,2,1,4,5,3,2,3,2,3,2,4,1,4,1,4,4,4,1,1,2,4,4};
provinces[1].setOwner(1);
dataL = new int[] {0,1,2,3,2,3,2,2,2,2,2,3,1,2,0,2,1,2,2,2,1,3,2,2,1,3,0,3,0,3,0,3,2,2,3,2,1,4,1,4,0,1,0,2,0,5,0,3,1,2,3,3,3,1,3,2,1,2,1,2,3,1,1,1,3,5,2,2,2,2,2,2,3,1,3,1,3,4,3,1,0,2,3,4};
provinces[1].setOwner(0);
provinces[1].setEntityCount(1);
provinces[2].setOwner(3);
provinces[2].setOwner(2);
provinces[2].setEntityCount(3);
provinces[3].setOwner(3);
provinces[3].setOwner(2);
provinces[3].setEntityCount(3);
provinces[4].setOwner(3);//Fabrik
provinces[4].setOwner(2);//Fabrik
provinces[4].setEntityCount(2);
provinces[5].setOwner(3);//Fabrik
provinces[5].setOwner(2);//Fabrik
provinces[5].setEntityCount(2);
provinces[6].setOwner(3);//Fabrik
provinces[6].setOwner(2);//Fabrik
provinces[6].setEntityCount(3);
provinces[7].setOwner(2);
provinces[7].setOwner(1);
provinces[7].setEntityCount(2);
provinces[8].setOwner(1);
provinces[8].setOwner(0);
provinces[8].setEntityCount(2);
provinces[9].setOwner(2);
provinces[9].setOwner(1);
provinces[9].setEntityCount(2);
provinces[10].setOwner(3);//Fabrik
provinces[10].setOwner(2);//Fabrik
provinces[10].setEntityCount(2);
provinces[11].setOwner(2);//Fabrik
provinces[11].setOwner(1);//Fabrik
provinces[11].setEntityCount(3);
provinces[12].setOwner(3);
provinces[12].setOwner(2);
provinces[12].setEntityCount(2);
provinces[13].setOwner(2);//Fabrik
provinces[13].setOwner(1);//Fabrik
provinces[13].setEntityCount(3);
provinces[14].setOwner(1);//Fabrik
provinces[14].setOwner(0);//Fabrik
provinces[14].setEntityCount(3);
provinces[15].setOwner(1);//Fabrik
provinces[15].setOwner(0);//Fabrik
provinces[15].setEntityCount(3);
provinces[16].setOwner(1);//Fabrik
provinces[16].setOwner(0);//Fabrik
provinces[16].setEntityCount(3);
provinces[17].setOwner(3);
provinces[17].setOwner(2);
provinces[17].setEntityCount(2);
provinces[18].setOwner(4);
provinces[18].setOwner(3);
provinces[18].setEntityCount(2);
provinces[19].setOwner(2);//Fabrik
provinces[19].setOwner(1);//Fabrik
provinces[19].setEntityCount(4);
provinces[20].setOwner(2);
provinces[20].setOwner(1);
provinces[20].setEntityCount(4);
provinces[21].setOwner(1);
provinces[21].setOwner(0);
provinces[21].setEntityCount(1);
provinces[22].setOwner(1);//Fabrik
provinces[22].setOwner(0);//Fabrik
provinces[22].setEntityCount(2);
provinces[23].setOwner(1);
provinces[23].setOwner(0);
provinces[23].setEntityCount(5);
provinces[24].setOwner(1);
provinces[24].setOwner(0);
provinces[24].setEntityCount(3);
provinces[25].setOwner(2);
provinces[25].setOwner(1);
provinces[25].setEntityCount(2);
provinces[26].setOwner(4);//Fabrik
provinces[26].setOwner(3);//Fabrik
provinces[26].setEntityCount(3);
provinces[27].setOwner(4);
provinces[27].setOwner(3);
provinces[27].setEntityCount(1);
provinces[28].setOwner(4);//Fabrik
provinces[28].setOwner(3);//Fabrik
provinces[28].setEntityCount(2);
provinces[29].setOwner(2);//Fabrik
provinces[29].setOwner(1);//Fabrik
provinces[29].setEntityCount(2);
provinces[30].setOwner(2);
provinces[30].setOwner(1);
provinces[30].setEntityCount(2);
provinces[31].setOwner(4);
provinces[31].setOwner(3);
provinces[31].setEntityCount(1);
provinces[32].setOwner(2);
provinces[32].setOwner(1);
provinces[32].setEntityCount(1);
provinces[33].setOwner(4);
provinces[33].setOwner(3);
provinces[33].setEntityCount(5);
provinces[34].setOwner(3);
provinces[34].setOwner(2);
provinces[34].setEntityCount(2);
provinces[35].setOwner(3);
provinces[35].setOwner(2);
provinces[35].setEntityCount(2);
provinces[36].setOwner(3);
provinces[36].setOwner(2);
provinces[36].setEntityCount(2);
provinces[37].setOwner(4);
provinces[37].setOwner(3);
provinces[37].setEntityCount(1);
provinces[38].setOwner(4);//Fabrik
provinces[38].setOwner(3);//Fabrik
provinces[38].setEntityCount(1);
provinces[39].setOwner(4);
provinces[39].setOwner(3);
provinces[39].setEntityCount(4);
provinces[40].setOwner(4);
provinces[40].setOwner(3);
provinces[40].setEntityCount(1);
provinces[41].setOwner(1);//Fabrik
provinces[41].setOwner(0);//Fabrik
provinces[41].setEntityCount(2);
provinces[42].setOwner(4);
provinces[42].setOwner(3);
provinces[42].setEntityCount(4);
} else if(players.length==5) {
/*
@ -302,90 +302,90 @@ public abstract class GeneralMap extends World implements ButtonEvent
Spieler 4 ist als viertes dran und bekommt eine Karte; Hauptstadt:20
Spieler 5 ist als fünftes dran und bekommt zwei Karte; Hauptstadt:41
*/
dataL = new int[] {3,1,1,2,4,2,2,2,2,2,2,2,2,4,4,1,2,2,4,1,4,3,3,1,1,4,1,2,3,3,1,2,2,3,4,2,4,5,4,3,2,2,3,5,3,3,1,2,3,3,3,2,2,3,5,2,5,3,5,3,1,3,1,3,4,1,5,1,5,1,5,2,3,2,4,2,5,2,1,2,5,4,5,2};
provinces[1].setOwner(3);
dataL = new int[] {2,1,0,2,3,2,1,2,1,2,1,2,1,4,3,1,1,2,3,1,3,3,2,1,0,4,0,2,2,3,0,2,1,3,3,2,3,5,3,3,1,2,2,5,2,3,0,2,2,3,2,2,1,3,4,2,4,3,4,3,0,3,0,3,3,1,4,1,4,1,4,2,2,2,3,2,4,2,0,2,4,4,4,2};
provinces[1].setOwner(2);
provinces[1].setEntityCount(1);
provinces[2].setOwner(1);
provinces[2].setOwner(0);
provinces[2].setEntityCount(2);
provinces[3].setOwner(4);
provinces[3].setOwner(3);
provinces[3].setEntityCount(2);
provinces[4].setOwner(2);//Fabrik
provinces[4].setOwner(1);//Fabrik
provinces[4].setEntityCount(2);
provinces[5].setOwner(2);//Fabrik
provinces[5].setOwner(1);//Fabrik
provinces[5].setEntityCount(2);
provinces[6].setOwner(2);//Fabrik
provinces[6].setOwner(1);//Fabrik
provinces[6].setEntityCount(2);
provinces[7].setOwner(2);
provinces[7].setOwner(1);
provinces[7].setEntityCount(4);
provinces[8].setOwner(4);
provinces[8].setOwner(3);
provinces[8].setEntityCount(1);
provinces[9].setOwner(2);
provinces[9].setOwner(1);
provinces[9].setEntityCount(2);
provinces[10].setOwner(4);
provinces[10].setOwner(3);
provinces[10].setEntityCount(1);
provinces[11].setOwner(4);//Fabrik
provinces[11].setOwner(3);//Fabrik
provinces[11].setEntityCount(3);
provinces[12].setOwner(3);
provinces[12].setOwner(2);
provinces[12].setEntityCount(1);
provinces[13].setOwner(1);
provinces[13].setOwner(0);
provinces[13].setEntityCount(4);
provinces[14].setOwner(1);//Fabrik
provinces[14].setOwner(0);//Fabrik
provinces[14].setEntityCount(2);
provinces[15].setOwner(3);//Fabrik
provinces[15].setOwner(2);//Fabrik
provinces[15].setEntityCount(3);
provinces[16].setOwner(1);//Fabrik
provinces[16].setOwner(0);//Fabrik
provinces[16].setEntityCount(2);
provinces[17].setOwner(2);
provinces[17].setOwner(1);
provinces[17].setEntityCount(3);
provinces[18].setOwner(4);
provinces[18].setOwner(3);
provinces[18].setEntityCount(2);
provinces[19].setOwner(4);//Fabrik
provinces[19].setOwner(3);//Fabrik
provinces[19].setEntityCount(5);
provinces[20].setOwner(4);
provinces[20].setOwner(3);
provinces[20].setEntityCount(3);
provinces[21].setOwner(2);
provinces[21].setOwner(1);
provinces[21].setEntityCount(2);
provinces[22].setOwner(3);//Fabrik
provinces[22].setOwner(2);//Fabrik
provinces[22].setEntityCount(5);
provinces[23].setOwner(3);
provinces[23].setOwner(2);
provinces[23].setEntityCount(3);
provinces[24].setOwner(1);
provinces[24].setOwner(0);
provinces[24].setEntityCount(2);
provinces[25].setOwner(3);
provinces[25].setOwner(2);
provinces[25].setEntityCount(3);
provinces[26].setOwner(3);//Fabrik
provinces[26].setOwner(2);//Fabrik
provinces[26].setEntityCount(2);
provinces[27].setOwner(2);
provinces[27].setOwner(1);
provinces[27].setEntityCount(3);
provinces[28].setOwner(5);//Fabrik
provinces[28].setOwner(4);//Fabrik
provinces[28].setEntityCount(2);
provinces[29].setOwner(5);//Fabrik
provinces[29].setOwner(4);//Fabrik
provinces[29].setEntityCount(3);
provinces[30].setOwner(5);
provinces[30].setOwner(4);
provinces[30].setEntityCount(3);
provinces[31].setOwner(1);
provinces[31].setOwner(0);
provinces[31].setEntityCount(3);
provinces[32].setOwner(1);
provinces[32].setOwner(0);
provinces[32].setEntityCount(3);
provinces[33].setOwner(4);
provinces[33].setOwner(3);
provinces[33].setEntityCount(1);
provinces[34].setOwner(5);
provinces[34].setOwner(4);
provinces[34].setEntityCount(1);
provinces[35].setOwner(5);
provinces[35].setOwner(4);
provinces[35].setEntityCount(1);
provinces[36].setOwner(5);
provinces[36].setOwner(4);
provinces[36].setEntityCount(2);
provinces[37].setOwner(3);
provinces[37].setOwner(2);
provinces[37].setEntityCount(2);
provinces[38].setOwner(4);//Fabrik
provinces[38].setOwner(3);//Fabrik
provinces[38].setEntityCount(2);
provinces[39].setOwner(5);
provinces[39].setOwner(4);
provinces[39].setEntityCount(2);
provinces[40].setOwner(1);
provinces[40].setOwner(0);
provinces[40].setEntityCount(2);
provinces[41].setOwner(5);//Fabrik
provinces[41].setOwner(4);//Fabrik
provinces[41].setEntityCount(4);
provinces[42].setOwner(5);
provinces[42].setOwner(4);
provinces[42].setEntityCount(2);
}
int errors = 0;

@ -1,15 +1,18 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
Klasse der Standard-Welt
(Also die normale Weltkarte mit allen Kontinenten)
Klasse der Standard-Welt
(Also die normale Weltkarte mit allen Kontinenten)
@author GruenerWal, MaxiJohl
@version 0.3.0
@author GruenerWal, MaxiJohl
@version 1.0.0
*/
public class Map_World extends GeneralMap
{
/**
Anzahl der Provinzen.
*/
/**
Konstruktor der Weltkarte;
@ -20,6 +23,9 @@ public class Map_World extends GeneralMap
{
super(playerList,colorList);
setBackground("MapWorld.png");
provinceCount = 42;
armyMinimum = 3;
/*
Hier werden später sämtliche Provinzen der Standard-Map erstellt.
Dies funktioniert folgendermassen:
@ -38,9 +44,10 @@ public class Map_World extends GeneralMap
~GruenerWal
*/
continentBoni = new int[] {0,5,5,2,3,7,2};
// Festlegung der Provinz-Anzahl
provinceCount = 42;
provinces = new Province[provinceCount + 1];
// Implementierung sämtlicher Provinzen

Loading…
Cancel
Save