dice-cheat entfernt, fight korrigiert, ausgabe verbessert, Player.redraw
erstellt, Province-redraw verändert
master
SariusRu 9 years ago
parent a232090d63
commit 2cd763d242

@ -41,8 +41,8 @@ public class Dice_Defender extends Dice
{
diceEyesDefender[0] = (int) (Math.random() * 6 +1);
diceEyesDefender[1] = (int) (Math.random()* 6 +1);
System.out.println(diceEyesDefender[0]);
System.out.println(diceEyesDefender[1]);
// System.out.println(diceEyesDefender[0]);
// System.out.println(diceEyesDefender[1]);
return diceEyesDefender;
}
Arrays.sort(diceEyesDefender);
@ -51,28 +51,4 @@ public class Dice_Defender extends Dice
}
public int[] max_defender(int troupNumberDefender)
{
if(troupNumberDefender == 1)
{
diceEyesDefender[0] = (int) (Math.random() * 2 +4);
return diceEyesDefender;
}
if(troupNumberDefender >=2 )
{
diceEyesDefender[0] = (int) (Math.random() * 2 +4);
diceEyesDefender[1] = (int) (Math.random()* 2 +4);
System.out.println(diceEyesDefender[0]);
System.out.println(diceEyesDefender[1]);
return diceEyesDefender;
}
Arrays.sort(diceEyesDefender);
return diceEyesDefender;
}
}

@ -39,7 +39,7 @@ public class Dice_Offender extends Dice
if(troupNumberOffender == 2)
{
diceEyesOffender[0] = (int) (Math.random()*6+1);
System.out.println(diceEyesOffender[0]);
// System.out.println(diceEyesOffender[0]);
return diceEyesOffender;
}
@ -47,8 +47,8 @@ public class Dice_Offender extends Dice
{
diceEyesOffender[0] = (int) (Math.random() * 6 +1);
diceEyesOffender[1] = (int) (Math.random()* 6 +1);
System.out.println(diceEyesOffender[0]);
System.out.println(diceEyesOffender[1]);
// System.out.println(diceEyesOffender[0]);
// System.out.println(diceEyesOffender[1]);
return diceEyesOffender;
}
if(troupNumberOffender > 3)
@ -56,9 +56,9 @@ public class Dice_Offender extends Dice
diceEyesOffender[0] = (int) (Math.random() * 6 +1);
diceEyesOffender[1] = (int) (Math.random()* 6 +1);
diceEyesOffender[2] = (int) (Math.random()* 6 + 1);
System.out.println(diceEyesOffender[0]);
System.out.println(diceEyesOffender[1]);
System.out.println(diceEyesOffender[2]);
// System.out.println(diceEyesOffender[0]);
// System.out.println(diceEyesOffender[1]);
// System.out.println(diceEyesOffender[2]);
return diceEyesOffender;
}
Arrays.sort(diceEyesOffender);
@ -67,44 +67,4 @@ public class Dice_Offender extends Dice
}
public int[] max_offender(int troupNumberOffender)
{
if(troupNumberOffender == 1)
{
System.out.println("Mit einer verbleibenden Truppe auff dem Feld kann man nicht angreifen!");
}
if(troupNumberOffender == 2)
{
diceEyesOffender[0] = (int) (Math.random()*2+5);
System.out.println(diceEyesOffender[0]);
return diceEyesOffender;
}
if(troupNumberOffender == 3)
{
diceEyesOffender[0] = (int) (Math.random() * 2 +5);
diceEyesOffender[1] = (int) (Math.random()* 2 +5);
System.out.println(diceEyesOffender[0]);
System.out.println(diceEyesOffender[1]);
return diceEyesOffender;
}
if(troupNumberOffender > 3)
{
diceEyesOffender[0] = (int) (Math.random() * 2 +5);
diceEyesOffender[1] = (int) (Math.random()* 2 +5);
diceEyesOffender[2] = (int) (Math.random()* 2 + 5);
System.out.println(diceEyesOffender[0]);
System.out.println(diceEyesOffender[1]);
System.out.println(diceEyesOffender[2]);
return diceEyesOffender;
}
Arrays.sort(diceEyesOffender);
return diceEyesOffender;
}
}

@ -1,5 +1,6 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.Arrays;
import javax.swing.JOptionPane;
/**
* Write a description of class Fight here.
@ -16,16 +17,31 @@ public class Fight extends Map_World
*/
Province offenderProvince;
Province defenderProvince;
String maxDiceOffender = "";
String maxDiceDefender = "";
public Fight(String[] playerList, int[] colorList)
{
super(playerList,colorList);
}
public void test()
{
provinces[1].setEntityCount(10);
provinces[2].setEntityCount(20);
provinces[1].setOwner(1);
provinces[2].setOwner(2);
provinces[1].redrawProvince();
provinces[2].redrawProvince();
}
public void act()
{
if(offenderProvince == null)
{
OffenderProvince();
}
else
@ -41,7 +57,7 @@ public class Fight extends Map_World
if (provinces[i].hasClicked() == true)
{
offenderProvince = provinces[i];
System.out.println("1");
// System.out.println("Die Provinz " + provinces[i].getDisplayName() + " wurde als angreifende Provinz ausgewählt! Sie gehört Spieler" + provinces[i].getOwner());
}
}
}
@ -54,7 +70,7 @@ public class Fight extends Map_World
if (provinces[i].hasClicked() == true)//&& defenderProvince != offenderProvince)
{
defenderProvince = provinces[i];
System.out.println("2");
// System.out.println("Die Provinz " + provinces[i].getDisplayName() + " wurde als verteidigende Provinz ausgewählt! Sie gehört Spieler" + provinces[i].getOwner());
chooser();
break;
}
@ -64,48 +80,84 @@ public class Fight extends Map_World
private void chooser()
{
Dice_Offender diceOffender = new Dice_Offender();
int[] maxDiceOffender = diceOffender.max_offender(offenderProvince.getEntityCount());
System.out.println("Es wird gewürfelt!");
Dice_Offender diceOffender = new Dice_Offender();
// System.out.println("Der Angreifer ereichte folgende Würfelzahlen:");
int[] maxDiceOffenderArray = diceOffender.dice_offender(offenderProvince.getEntityCount());
Dice_Defender diceDefender = new Dice_Defender();
int[] maxDiceDefender = diceDefender.max_defender(defenderProvince.getEntityCount());
Arrays.sort(maxDiceOffender);
Arrays.sort(maxDiceDefender);
decider(maxDiceOffender, maxDiceDefender);
// System.out.println("Der Verteidiger ereichte folgende Würfelzahlen:");
int[] maxDiceDefenderArray = diceDefender.dice_defender(defenderProvince.getEntityCount());
Arrays.sort(maxDiceOffenderArray);
Arrays.sort(maxDiceDefenderArray);
for(int i = 0;i<3;i++)
{
if(i == 0)
{
maxDiceOffender = "" + maxDiceOffenderArray[i];
}
else
{
maxDiceOffender = maxDiceOffender + ";" + maxDiceOffenderArray[i];
}
}
for(int i = 0;i<2;i++)
{
if(i == 0)
{
maxDiceDefender = "" + maxDiceDefenderArray[i];
}
else
{
maxDiceDefender = maxDiceDefender + ";" + maxDiceDefenderArray[i];
}
}
JOptionPane.showMessageDialog(null,"Es wurde gewürfelt. Der Angreifer erreichte folgende Würfelzahlen: " + maxDiceOffender + "\n Der Verteidiger erreichte diese Würfelzahlen: " + maxDiceDefender);
diceOffender = null;
diceDefender = null;
decider(maxDiceOffenderArray, maxDiceDefenderArray);
}
private void decider(int[] maxDiceOffender, int [] maxDiceDefender)
{
int maxDefender = maxDiceDefender[1];
int maxOffender = maxDiceOffender[2];
if (maxOffender>maxDefender && defenderProvince.getEntityCount()>1)
if (maxOffender > maxDefender && defenderProvince.getEntityCount()>1)
{
int EntitiesOffender = offenderProvince.getEntityCount();
int EntitiesDefender = defenderProvince.getEntityCount();
defenderProvince.setEntityCount(EntitiesDefender - 1);
defenderProvince.setEntityCount(EntitiesDefender - 1);
JOptionPane.showMessageDialog(null,"Somit gewinnt der Angreifer (Spieler " + offenderProvince.getOwner() + ").Dem Verteidiger (Spieler " + defenderProvince.getOwner() + ") wird eine Einheit abgezogen. Er hat nun noch " + defenderProvince.getEntityCount() + " Einheiten");
}
if (maxOffender<maxDefender && offenderProvince.getEntityCount()>1)
if (maxOffender < maxDefender && offenderProvince.getEntityCount()>1)
{
int EntitiesOffender = offenderProvince.getEntityCount();
int EntitiesDefender = defenderProvince.getEntityCount();
offenderProvince.setEntityCount(EntitiesOffender - 1);
offenderProvince.setEntityCount(EntitiesOffender - 1);
JOptionPane.showMessageDialog(null,"Somit gewinnt der Verteidiger (Spieler " + defenderProvince.getOwner() + ").Dem Angreifer (Spieler " + defenderProvince.getOwner() + ") wird eine Einheit abgezogen. Er hat nun noch " + offenderProvince.getEntityCount() + " Einheiten");
}
if (maxOffender>maxDefender && defenderProvince.getEntityCount()==1)
if (maxOffender == maxDefender && offenderProvince.getEntityCount()>1)
{
defenderProvince.setOwner(offenderProvince.getOwner());
defenderProvince.setEntityCount(0);
int EntitiesOffender = offenderProvince.getEntityCount();
int EntitiesDefender = defenderProvince.getEntityCount();
offenderProvince.setEntityCount(EntitiesOffender - 1);
JOptionPane.showMessageDialog(null,"Da es unentschieden ist, gewinnt der Verteidiger (Spieler " + defenderProvince.getOwner() + ").Dem Angreifer (Spieler " + defenderProvince.getOwner() + ") wird eine Einheit abgezogen. Er hat nun noch " + offenderProvince.getEntityCount() + " Einheiten");
}
if (maxOffender>maxDefender && offenderProvince.getEntityCount()==1)
if (maxOffender>maxDefender && defenderProvince.getEntityCount()==1)
{
offenderProvince.setOwner(defenderProvince.getOwner());
offenderProvince.setEntityCount(0);
defenderProvince.setOwner(offenderProvince.getOwner());
defenderProvince.setEntityCount(0);
JOptionPane.showMessageDialog(null,"Somit gewinnt der Angreifer (Spieler " + offenderProvince.getOwner() + "). Die Provinz gehört fortan dem Angreifer (" + offenderProvince.getOwner() + ")");
}
System.out.println("3");
offenderProvince = null;
defenderProvince = null;
}
}

@ -1,4 +1,5 @@
import greenfoot.*;
import java.awt.Color;
/**
* Write a description of class Player here.
@ -20,6 +21,10 @@ public class Player extends Actor
boolean [] pBesitzer = new boolean [42];
boolean gotProv = false;
boolean lostProv = false;
int identity;
String name;
int color;
int textsize;
private String n;
private int c;
@ -126,10 +131,12 @@ public class Player extends Actor
{
stats[3]+= gotEnt;
}
public void lostEntity()
{
stats[4]+=1;
}
private void maxEntities(int entNumber)
{
if (stats[5]< entNumber)
@ -137,6 +144,7 @@ public class Player extends Actor
stats[5]=entNumber;
}
}
public boolean[] getMyProvinces()
{
GeneralMap w= getWorld();
@ -188,13 +196,78 @@ public class Player extends Actor
{
return lostProv;
}
public int[] getStatistics()
{
return stats;
}
private void redrawPlayer()
public int setColor(int c)
{
color = c;
return color;
}
public void redrawPlayer()
{
int textSize = 20;
GreenfootImage statistics = new GreenfootImage(137,120);
GreenfootImage Name = new GreenfootImage(n,textSize,new Color(0,0,0),new Color(1.0f,1.0f,1.0f,0.5f));
statistics.drawImage(Name,0,0);
setImage(statistics);
oDecide(statistics,textSize);
}
private void oDecide(GreenfootImage statistics,int textSize)
{
GreenfootImage flag = new GreenfootImage("images\\BlaueArmee.jpg");
redraw(statistics,flag,textSize);
switch(color)
{
case 2:
flag = new GreenfootImage("images\\BlaueArmee.jpg");
redraw(statistics,flag,textSize);
break;
case 5:
flag = new GreenfootImage("images\\GelbeArmee.jpg");
redraw(statistics,flag,textSize);
break;
case 6:
flag = new GreenfootImage("images\\LilaArmee.jpg");
redraw(statistics,flag,textSize);
break;
case 4:
flag = new GreenfootImage("images\\RoteArmee.jpg");
redraw(statistics,flag,textSize);
break;
case 1:
flag = new GreenfootImage("images\\SchwarzeArmee.jpg");
redraw(statistics,flag,textSize);
break;
case 3:
flag = new GreenfootImage("images\\Gr++neArmee.jpg");
redraw(statistics,flag,textSize);
break;
}
}
private void redraw(GreenfootImage statistics,GreenfootImage flag, int textSize)
{
//Platzhalter
int x=0;
flag.scale(137,100);
statistics.drawImage(flag,0,textSize);
GreenfootImage playerStatistics = new GreenfootImage(stats[0] + "||" + stats[1] + "||" + stats[2],textSize,new Color(0,0,0),new Color(1.0f,1.0f,1.0f,0.5f));
GreenfootImage playerStatistics2 = new GreenfootImage(stats[3] + "||" + stats[4] + "||" + stats[5],textSize,new Color(0,0,0),new Color(1.0f,1.0f,1.0f,0.5f));
statistics.drawImage(playerStatistics, 0, 123);
statistics.drawImage(playerStatistics2, 0, 123 + textSize);
setImage(statistics);
}
}

@ -12,19 +12,19 @@ public class Province extends Actor
@Override public GeneralMap getWorld() {
return (GeneralMap) super.getWorld();
}
private int stars = 1;
private int provinceID;
private String displayName;
private int owner;
private int owner = 0;
private boolean[] nextProvinces;
private int continentID;
private int xPos;
private int yPos;
private int eCount;
private boolean clicked = false;
/**
* Überprüft, ob die Provinz angeklickt wurde.
*/
@ -178,34 +178,43 @@ public class Province extends Actor
public void oDecide(GreenfootImage province,int textSize)
{
String ownerString;
switch(owner)
if(owner == 0)
{
case 1:
ownerString = "schwarz";
eCalculate(province,ownerString,textSize);
break;
case 2:
ownerString = "rot";
eCalculate(province,ownerString,textSize);
break;
case 3:
ownerString = "blau";
eCalculate(province,ownerString,textSize);
break;
case 4:
ownerString = "gelb";
eCalculate(province,ownerString,textSize);
break;
case 5:
ownerString = "gr++n";
eCalculate(province,ownerString,textSize);
break;
case 6:
ownerString = "lila";
eCalculate(province,ownerString,textSize);
}
else
{
switch(owner)
{
case 1:
ownerString = "schwarz";
eCalculate(province,ownerString,textSize);
break;
case 2:
ownerString = "rot";
eCalculate(province,ownerString,textSize);
break;
case 3:
ownerString = "blau";
eCalculate(province,ownerString,textSize);
break;
case 4:
ownerString = "gelb";
eCalculate(province,ownerString,textSize);
break;
case 5:
ownerString = "gr++n";
eCalculate(province,ownerString,textSize);
break;
case 6:
ownerString = "lila";
eCalculate(province,ownerString,textSize);
break;
}
}
}
private void eCalculate(GreenfootImage province, String ownerString,int textSize)
@ -215,6 +224,10 @@ public class Province extends Actor
tank.scale(textSize,textSize);
if(eCountTanks <= 3)
{
if(eCountTanks == 0)
{
}
if(eCountTanks == 1)
{
province.drawImage(tank,0,textSize);
@ -267,6 +280,6 @@ public class Province extends Actor
clicked = false;
return b;
}
}

Loading…
Cancel
Save