Province Update

Update vom Master
pull/60/head
Felix Stupp 10 years ago committed by GitHub
parent 0e9bd093d2
commit dd1efe3836

@ -9,277 +9,520 @@ import java.awt.Color;
*/ */
public class Province extends Actor public class Province extends Actor
{ {
@Override public GeneralMap getWorld() { @Override public GeneralMap getWorld() {
return (GeneralMap) super.getWorld(); return (GeneralMap) super.getWorld();
} }
private int stars = 1; private int stars = 1;
private int provinceID; private int provinceID;
private String displayName; private String displayName;
private int owner = 0; private int owner = 0;
private boolean[] nextProvinces; private boolean[] nextProvinces;
private int continentID; private int continentID;
private int xPos; private int xPos;
private int yPos; private int yPos;
private int eCount; private int eCount;
private boolean clicked = false; private boolean clicked = false;
/**
/** * Überprüft, ob die Provinz angeklickt wurde.
* Überprüft, ob die Provinz angeklickt wurde. */
*/ public void act()
public void act() {
{ if(Greenfoot.mouseClicked(this)) {
if(Greenfoot.mouseClicked(this)) { clicked = true;
clicked = true; }
} }
}
// Haupt-Konstruktor
// Haupt-Konstruktor public Province(int pID, int cID, int x, int y, int st, String s1, int[] ia1)
public Province(int pID, int cID, int x, int y, int st, String s1, int[] ia1) {
{ provinceID = pID;
provinceID = pID; continentID = cID;
continentID = cID; xPos = x;
xPos = x; yPos = y;
yPos = y; if(st > 0) {
if(st > 0) { stars = st;
stars = st; }
} displayName = s1;
displayName = s1; // Der Teil, der sich um die Konvertierung des int-Array in ein boolean-Array kümmert.
// Der Teil, der sich um die Konvertierung des int-Array in ein boolean-Array kümmert. int maxNum = 0;
int maxNum = 0; for(int i = 0; i < ia1.length; i++) {
for(int i = 0; i < ia1.length; i++) { if(maxNum < ia1[i]) {
if(maxNum < ia1[i]) { maxNum = ia1[i];
maxNum = ia1[i]; }
} }
} nextProvinces = new boolean[maxNum+1];
nextProvinces = new boolean[maxNum+1]; for(int i = 0; i < ia1.length; i++) {
for(int i = 0; i < ia1.length; i++) { if(ia1[i] >= 0) {
if(ia1[i] >= 0) { nextProvinces[ia1[i]] = true;
nextProvinces[ia1[i]] = true; }
} }
} }
}
// Zweiter Konstruktor, um auch das boolean-Array gegebenenfalls verwenden zu könnnen.
// Zweiter Konstruktor, um auch das boolean-Array gegebenenfalls verwenden zu könnnen. public Province(int pID, int cID, int x, int y, int st, String s1, boolean[] ba1)
public Province(int pID, int cID, int x, int y, int st, String s1, boolean[] ba1) {
{ provinceID = pID;
provinceID = pID; continentID = cID;
continentID = cID; xPos = x;
xPos = x; yPos = y;
yPos = y; if(st > 0) {
if(st > 0) { stars = st;
stars = st; }
} displayName = s1;
displayName = s1; nextProvinces = Utils.copyArray(ba1);
nextProvinces = Utils.copyArray(ba1); }
}
// Liefert die X-Position als Integer
// Liefert die X-Position als Integer public int getXPos()
public int getXPos() {
{ return xPos;
return xPos; }
}
// Liefert die Y-Position als Integer
// Liefert die Y-Position als Integer public int getYPos()
public int getYPos() {
{ return yPos;
return yPos; }
}
// Liefert die Provinz-ID als Integer
// Liefert die Provinz-ID als Integer public int getID()
public int getID() {
{ return provinceID;
return provinceID; }
}
// Liefert die Kontinent-ID als Integer
// Liefert die Kontinent-ID als Integer public int getContinentID()
public int getContinentID() {
{ return continentID;
return continentID; }
}
// Fragt ab, ob die angegebene Provinz in der Nähe von dieser liegt.
// Fragt ab, ob die angegebene Provinz in der Nähe von dieser liegt. public boolean isProvinceNear(int i) {
public boolean isProvinceNear(int i) { if(i >= nextProvinces.length) {
if(i >= nextProvinces.length) { return false;
return false; }
} return nextProvinces[i];
return nextProvinces[i]; }
}
// Liefert den Anzeigenamen als String
// Liefert den Anzeigenamen als String public String getDisplayName()
public String getDisplayName() {
{ return displayName;
return displayName; }
}
// Liefert die Sterne als Integer
// Liefert die Sterne als Integer public int getStars()
public int getStars() {
{ return stars;
return stars; }
}
// Liefert den Owner als String
// Liefert den Owner als String public int getOwner()
public int getOwner() {
{ return owner;
return owner; }
}
// Setzt den Owner, benötigt String
// Setzt den Owner, benötigt String public void setOwner(int o)
public void setOwner(int o) {
{ if(o < -1) {
if(o < -1) { o = -1;
o = -1; }
} owner = o;
owner = o; }
}
public int getEntityCount() {
public int getEntityCount() { return eCount;
return eCount; }
}
private void checkEntityCount() {
private void checkEntityCount() { if(eCount < 0) {
if(eCount < 0) { eCount = 0;
eCount = 0; }
} }
}
public int addToEntities(int a) {
public int addToEntities(int a) { eCount = eCount + a;
eCount = eCount + a; checkEntityCount();
checkEntityCount(); redrawProvince();
redrawProvince(); return eCount;
return eCount; }
}
public int removeFromEntities(int a) {
public int removeFromEntities(int a) { eCount = eCount - a;
eCount = eCount - a; checkEntityCount();
checkEntityCount(); redrawProvince();
redrawProvince(); return eCount;
return eCount; }
}
public int setEntityCount(int a) {
public int setEntityCount(int a) { eCount = a;
eCount = a; checkEntityCount();
checkEntityCount(); redrawProvince();
redrawProvince(); return eCount;
return eCount; }
}
public void redrawProvince()
public void redrawProvince() {
{ int textSize;
int textSize; textSize = 20;
textSize = 20; GreenfootImage province = new GreenfootImage(120,100);
GreenfootImage province = new GreenfootImage(120,100); GreenfootImage provinceName = new GreenfootImage(displayName,textSize,new Color(0,0,0),new Color(1.0f,1.0f,1.0f,0.5f));
GreenfootImage provinceName = new GreenfootImage(displayName,textSize,new Color(0,0,0),new Color(1.0f,1.0f,1.0f,0.5f)); province.drawImage(provinceName,0,0);
province.drawImage(provinceName,0,0); setImage(province);
oDecide(province,textSize); oDecide(province,textSize,owner,eCount);
}
}
public void oDecide(GreenfootImage province,int textSize)
{ public void oDecide(GreenfootImage province,int textSize, int owner, int eCount)
String ownerString; {
if(owner == 0) String ownerString;
{ if(owner == 0)
ownerString = "schwarz"; {
eCalculate(province,ownerString,textSize); ownerString = "schwarz";
} eCalculate(province,ownerString,textSize);
else }
{ else
switch(owner) {
{ switch(owner)
case 1: {
ownerString = "schwarz"; case 1:
eCalculate(province,ownerString,textSize); ownerString = "schwarz";
break; eCalculate(province,ownerString,textSize);
case 2: break;
ownerString = "rot"; case 2:
eCalculate(province,ownerString,textSize); ownerString = "rot";
break; eCalculate(province,ownerString,textSize);
case 3: break;
ownerString = "blau"; case 3:
eCalculate(province,ownerString,textSize); ownerString = "blau";
break; eCalculate(province,ownerString,textSize);
case 4: break;
ownerString = "gelb"; case 4:
eCalculate(province,ownerString,textSize); ownerString = "gelb";
break; eCalculate(province,ownerString,textSize);
case 5: break;
ownerString = "gr++n"; case 5:
eCalculate(province,ownerString,textSize); ownerString = "gr++n";
break; eCalculate(province,ownerString,textSize);
case 6: break;
ownerString = "lila"; case 6:
eCalculate(province,ownerString,textSize); ownerString = "lila";
break; eCalculate(province,ownerString,textSize);
break;
}
} }
}
} }
private void eCalculate(GreenfootImage province, String ownerString,int textSize) private void eCalculate(GreenfootImage province, String ownerString,int textSize)
{ {
int eCountTanks = eCount / 5; int eCountTanks = eCount / 5;
GreenfootImage tank = new GreenfootImage("images\\dickebertaskal-" + ownerString + ".png"); int eCountHorse = (eCount - (eCountTanks * 5))/3;
tank.scale(textSize,textSize); int eCountInf = eCount - (eCountTanks * 5) - (eCountHorse * 3);
if(eCountTanks <= 3)
{ if(eCountTanks >= 1 && eCountInf == 0 && eCountHorse == 0)
if(eCountTanks == 0) {
{ OnlyTanks(province,eCountTanks,ownerString,textSize);
}
} if(eCountTanks == 0 && eCountInf == 0 && eCountHorse != 0)
if(eCountTanks == 1) {
{ OnlyHorses(province,eCountHorse,ownerString,textSize);
province.drawImage(tank,0,textSize); }
} if(eCountTanks == 0 && eCountInf != 0 && eCountHorse == 0)
if(eCountTanks == 2) {
{ OnlyInf(province,eCountInf,ownerString,textSize);
province.drawImage(tank,0,textSize); }
province.drawImage(tank,textSize,textSize); if(eCountTanks == 0 && eCountInf != 0 && eCountHorse != 0)
} {
if(eCountTanks == 3) NoTanks(province,eCountInf,eCountHorse, ownerString, textSize);
{ }
province.drawImage(tank,0,textSize); if(eCountTanks != 0 && eCountInf != 0 && eCountHorse == 0)
province.drawImage(tank,textSize,textSize); {
province.drawImage(tank,textSize*2,textSize); NoHorse(province,eCountInf,eCountTanks, ownerString, textSize);
} }
} if(eCountTanks != 0 && eCountInf == 0 && eCountHorse != 0)
else {
{ NoInf(province,eCountInf,eCountTanks, ownerString, textSize);
GreenfootImage eCountTanksImage = new GreenfootImage(Integer.toString(eCountTanks) + "x",textSize,Color.BLACK,new Color(1.0f,1.0f,1.0f,0.5f)); }
province.drawImage(eCountTanksImage,0,textSize); if(eCountTanks == 0 && eCountInf == 0 && eCountHorse == 0)
province.drawImage(tank,45,textSize); {
} NoEntity(province, ownerString, textSize);
int eCountHorse = (eCount - (eCountTanks * 5))/3; }
GreenfootImage horse = new GreenfootImage("images\\pferdreiterskal-" + ownerString + ".png"); if(eCountTanks != 0 && eCountInf != 0 && eCountHorse != 0)
horse.scale(textSize,textSize); {
if(eCountHorse == 1) AllEntity(province, ownerString,eCountTanks, eCountHorse, eCountInf, textSize);
{ }
province.drawImage(horse,4*textSize,textSize);
} }
GreenfootImage Inf = new GreenfootImage("images\\infanterieskal-" + ownerString + ".png");
int eCountInf = eCount - (eCountTanks * 5) - (eCountHorse * 3); private void NoEntity(GreenfootImage province, String ownerString, int textSize)
Inf.scale(textSize,textSize); {
if(eCountInf <= 4)
{ }
if(eCountInf == 1)
{ private void OnlyTanks(GreenfootImage province,int eCountTanks, String ownerString, int textSize)
province.drawImage(Inf,5*textSize,textSize); {
} GreenfootImage tank = new GreenfootImage("images\\dickebertaskal-" + ownerString + ".png");
if(eCountInf == 2) tank.scale(textSize,textSize);
{ if(eCountTanks <= 3)
province.drawImage(Inf,5*textSize,textSize); {
province.drawImage(Inf,5*textSize,textSize); if(eCountTanks == 1)
} {
} province.drawImage(tank,0,textSize);
setImage(province); }
} if(eCountTanks == 2)
{
public boolean hasClicked() { province.drawImage(tank,0,textSize);
boolean b = clicked; province.drawImage(tank,textSize,textSize);
clicked = false; }
return b; if(eCountTanks == 3)
} {
province.drawImage(tank,0,textSize);
province.drawImage(tank,textSize,textSize);
province.drawImage(tank,textSize*2,textSize);
}
}
else
{
GreenfootImage eCountTanksImage = new GreenfootImage(Integer.toString(eCountTanks) + "x",textSize,Color.BLACK,new Color(1.0f,1.0f,1.0f,0.5f));
province.drawImage(eCountTanksImage,0,textSize);
province.drawImage(tank,eCountTanksImage.getWidth(),textSize);
}
setImage(province);
}
private void OnlyHorses(GreenfootImage province,int eCountHorse, String ownerString, int textSize)
{
GreenfootImage horse = new GreenfootImage("images\\pferdreiterskal-" + ownerString + ".png");
horse.scale(textSize,textSize);
province.drawImage(horse,0,textSize);
setImage(province);
}
private void OnlyInf(GreenfootImage province,int eCountInf, String ownerString, int textSize)
{
GreenfootImage Inf = new GreenfootImage("images\\infanterieskal-" + ownerString + ".png");
Inf.scale(textSize,textSize);
if(eCountInf == 1)
{
province.drawImage(Inf,0,textSize);
}
if(eCountInf == 2)
{
province.drawImage(Inf,0,textSize);
province.drawImage(Inf,textSize,textSize);
}
setImage(province);
}
private void NoTanks(GreenfootImage province,int eCountInf,int eCountHorse, String ownerString, int textSize)
{
GreenfootImage Inf = new GreenfootImage("images\\infanterieskal-" + ownerString + ".png");
Inf.scale(textSize,textSize);
GreenfootImage horse = new GreenfootImage("images\\pferdreiterskal-" + ownerString + ".png");
horse.scale(textSize,textSize);
province.drawImage(horse,0,textSize);
setImage(province);
if(eCountInf == 1)
{
province.drawImage(Inf,textSize,textSize);
}
if(eCountInf == 2)
{
province.drawImage(Inf,textSize,textSize);
province.drawImage(Inf,2*textSize,textSize);
}
setImage(province);
}
private void NoHorse(GreenfootImage province,int eCountInf,int eCountTanks, String ownerString, int textSize)
{
GreenfootImage Inf = new GreenfootImage("images\\infanterieskal-" + ownerString + ".png");
Inf.scale(textSize,textSize);
GreenfootImage tank = new GreenfootImage("images\\dickebertaskal-" + ownerString + ".png");
tank.scale(textSize,textSize);
if(eCountTanks <= 3)
{
if(eCountTanks == 1)
{
province.drawImage(tank,0,textSize);
}
if(eCountTanks == 2)
{
province.drawImage(tank,0,textSize);
province.drawImage(tank,textSize,textSize);
}
if(eCountTanks == 3)
{
province.drawImage(tank,0,textSize);
province.drawImage(tank,textSize,textSize);
province.drawImage(tank,textSize*2,textSize);
}
}
else
{
GreenfootImage eCountTanksImage = new GreenfootImage(Integer.toString(eCountTanks) + "x",textSize,Color.BLACK,new Color(1.0f,1.0f,1.0f,0.5f));
province.drawImage(eCountTanksImage,0,textSize);
province.drawImage(tank,eCountTanksImage.getWidth(),textSize);
}
if(eCountTanks<=3)
{
if(eCountInf == 1)
{
province.drawImage(Inf,eCountTanks * textSize,textSize);
}
if(eCountInf == 2)
{
province.drawImage(Inf,eCountTanks * textSize,textSize);
province.drawImage(Inf,eCountTanks * 2 *textSize,textSize);
}
}
if(eCountTanks>3)
{
if(eCountInf == 1)
{
GreenfootImage eCountTanksImage = new GreenfootImage(Integer.toString(eCountTanks) + "x",textSize,Color.BLACK,new Color(1.0f,1.0f,1.0f,0.5f));
province.drawImage(Inf,eCountTanksImage.getWidth() + textSize,textSize);
}
if(eCountInf == 2)
{
GreenfootImage eCountTanksImage = new GreenfootImage(Integer.toString(eCountTanks) + "x",textSize,Color.BLACK,new Color(1.0f,1.0f,1.0f,0.5f));
province.drawImage(Inf,eCountTanksImage.getWidth() + textSize,textSize);
province.drawImage(Inf,eCountTanksImage.getWidth() + (2 *textSize),textSize);
}
}
setImage(province);
}
private void NoInf(GreenfootImage province,int eCountHorse,int eCountTanks, String ownerString, int textSize)
{
GreenfootImage tank = new GreenfootImage("images\\dickebertaskal-" + ownerString + ".png");
tank.scale(textSize,textSize);
GreenfootImage horse = new GreenfootImage("images\\pferdreiterskal-" + ownerString + ".png");
horse.scale(textSize,textSize);
if(eCountTanks <= 3)
{
if(eCountTanks == 1)
{
province.drawImage(tank,0,textSize);
}
if(eCountTanks == 2)
{
province.drawImage(tank,0,textSize);
province.drawImage(tank,textSize,textSize);
}
if(eCountTanks == 3)
{
province.drawImage(tank,0,textSize);
province.drawImage(tank,textSize,textSize);
province.drawImage(tank,textSize*2,textSize);
}
}
else
{
GreenfootImage eCountTanksImage = new GreenfootImage(Integer.toString(eCountTanks) + "x",textSize,Color.BLACK,new Color(1.0f,1.0f,1.0f,0.5f));
province.drawImage(eCountTanksImage,0,textSize);
province.drawImage(tank,eCountTanksImage.getWidth(),textSize);
}
if(eCountTanks<=3)
{
province.drawImage(horse,eCountTanks * textSize,textSize);
setImage(province);
}
if(eCountTanks>3)
{
GreenfootImage eCountTanksImage = new GreenfootImage(Integer.toString(eCountTanks) + "x",textSize,Color.BLACK,new Color(1.0f,1.0f,1.0f,0.5f));
province.drawImage(horse,eCountTanksImage.getWidth() + textSize,textSize);
setImage(province);
}
setImage(province);
}
private void AllEntity(GreenfootImage province, String ownerString,int eCountTanks, int eCountHorse, int eCountInf,int textSize)
{
GreenfootImage tank = new GreenfootImage("images\\dickebertaskal-" + ownerString + ".png");
tank.scale(textSize,textSize);
GreenfootImage horse = new GreenfootImage("images\\pferdreiterskal-" + ownerString + ".png");
horse.scale(textSize,textSize);
GreenfootImage Inf = new GreenfootImage("images\\infanterieskal-" + ownerString + ".png");
Inf.scale(textSize,textSize);
if(eCountTanks <= 3)
{
if(eCountTanks == 1)
{
province.drawImage(tank,0,textSize);
}
if(eCountTanks == 2)
{
province.drawImage(tank,0,textSize);
province.drawImage(tank,textSize,textSize);
}
if(eCountTanks == 3)
{
province.drawImage(tank,0,textSize);
province.drawImage(tank,textSize,textSize);
province.drawImage(tank,textSize*2,textSize);
}
}
else
{
GreenfootImage eCountTanksImage = new GreenfootImage(Integer.toString(eCountTanks) + "x",textSize,Color.BLACK,new Color(1.0f,1.0f,1.0f,0.5f));
province.drawImage(eCountTanksImage,0,textSize);
province.drawImage(tank,eCountTanksImage.getWidth(),textSize);
}
if(eCountHorse == 1)
{
if(eCountTanks<=3)
{
province.drawImage(horse,eCountTanks * textSize,textSize);
if(eCountInf == 1)
{
province.drawImage(Inf,eCountTanks * textSize + textSize,textSize);
}
if(eCountInf == 2)
{
province.drawImage(Inf,eCountTanks * textSize + textSize + textSize,textSize);
}
setImage(province);
}
if(eCountTanks>3)
{
GreenfootImage eCountTanksImage = new GreenfootImage(Integer.toString(eCountTanks) + "x",textSize,Color.BLACK,new Color(1.0f,1.0f,1.0f,0.5f));
province.drawImage(horse,eCountTanksImage.getWidth() + textSize,textSize);
if(eCountInf == 1)
{
province.drawImage(Inf,eCountTanksImage.getWidth() + textSize + textSize,textSize);
}
if(eCountInf == 2)
{
province.drawImage(Inf,eCountTanksImage.getWidth() + textSize + textSize + textSize + textSize,textSize);
}
setImage(province);
}
}
setImage(province);
}
public boolean hasClicked()
{
boolean b = clicked;
clicked = false;
return b;
}
} }

Loading…
Cancel
Save