Merge branch 'GeneralMapErweiterung' into GeneralMap-Player
commit
e2985ad4aa
@ -1,95 +0,0 @@
|
||||
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
import greenfoot.MouseInfo.*;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
/**
|
||||
* Schubst Einheiten umher.
|
||||
*
|
||||
* @author MaxiJohl, GruenerWal
|
||||
* @version 1.1.0
|
||||
*/
|
||||
|
||||
public class ArmySchubser extends Map_World
|
||||
{
|
||||
static Province savedProvince = null;
|
||||
|
||||
/**
|
||||
* Konstruktor für ArmySchubser.
|
||||
*
|
||||
* NICHT BENUTZEN!
|
||||
* Sämtliche benötigten Methoden sind static!
|
||||
*/
|
||||
public ArmySchubser(String[] playerList, int[] colorList)
|
||||
{
|
||||
super(playerList,colorList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nimmt zwei Provinzen entgegen, und fragt, wieviele Einheiten vom ersten zum zweiten Eintrag verschoben werden sollen.
|
||||
* Überprüft, ob eine Verschiebung möglich ist und führt sie bei Erfolg aus.
|
||||
*/
|
||||
public void moveEntities(Province sourceProvince, Province destinationProvince)
|
||||
{
|
||||
String toMoveString = JOptionPane.showInputDialog(null, "Wieviele Einheiten willst du verschieben?");
|
||||
Integer entitiesToMove = Integer.valueOf(toMoveString);
|
||||
|
||||
if ( entitiesToMove != null )
|
||||
{
|
||||
if ( (sourceProvince.getEntityCount() - entitiesToMove) > 0)
|
||||
{
|
||||
sourceProvince.removeFromEntities(entitiesToMove);
|
||||
destinationProvince.addToEntities(entitiesToMove);
|
||||
JOptionPane.showMessageDialog(null,"Einheiten erfolgreich verschoben, Kommandant " + getPlayerName() + ".");
|
||||
}
|
||||
|
||||
else if ( (sourceProvince.getEntityCount() - entitiesToMove) <= 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Du hast nicht genügend Einheiten, um die gewünschte Anzahl von " + sourceProvince.getDisplayName() + " nach " + destinationProvince.getDisplayName() + " zu verschieben, Köhler.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert ein gegebene Provinz als savedProvince ein, insofern dieser Platz nicht bereits belegt ist.
|
||||
* Ist er das, so wird überprüft, ob eine neue, an savedProvince angrenzende Provinz angeklickt wurde.
|
||||
* Ist dies der Fall, werden beide Provinzen an moveEntities übergeben.
|
||||
*/
|
||||
public void useProvincesToMove(Province givenProvince)
|
||||
{
|
||||
if (savedProvince == null)
|
||||
{
|
||||
savedProvince = givenProvince;
|
||||
}
|
||||
|
||||
else if ((savedProvince != null) && (givenProvince != savedProvince) && (savedProvince.getOwner() == givenProvince.getOwner()) && (savedProvince.getOwner() == currentPlayer) )
|
||||
{
|
||||
if (givenProvince.isProvinceNear(savedProvince.getID()) == true)
|
||||
{
|
||||
moveEntities(savedProvince,givenProvince);
|
||||
}
|
||||
|
||||
savedProvince = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Überprüft, ob eine Provinz angeklickt wurde.
|
||||
* Wenn ja, wird diese als clickedProvince eingespeichert und useProvincesToMove aufgerufen.
|
||||
*
|
||||
* Kommt nachher in die GeneralMap!
|
||||
*/
|
||||
public void act()
|
||||
{
|
||||
Province clickedProvince;
|
||||
|
||||
for ( int i = 1; i <= (provinces.length - 1); i++)
|
||||
{
|
||||
if (provinces[i].hasClicked() == true)
|
||||
{
|
||||
clickedProvince = provinces[i];
|
||||
useProvincesToMove(clickedProvince);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Write a description of class Fight here.
|
||||
*
|
||||
* @author (your name)
|
||||
* @version (a version number or a date)
|
||||
*/
|
||||
public class Fight extends Map_World
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Fight.
|
||||
*
|
||||
*/
|
||||
Province offenderProvince;
|
||||
Province defenderProvince;
|
||||
|
||||
public Fight(String[] playerList, int[] colorList)
|
||||
{
|
||||
super(playerList,colorList);
|
||||
}
|
||||
|
||||
public void act()
|
||||
{
|
||||
if(offenderProvince == null)
|
||||
{
|
||||
OffenderProvince();
|
||||
}
|
||||
else
|
||||
{
|
||||
defenderProvince();
|
||||
}
|
||||
}
|
||||
|
||||
private void OffenderProvince()
|
||||
{
|
||||
for ( int i = 1; i <= provinceCount; i++)
|
||||
{
|
||||
if (provinces[i].hasClicked() == true)
|
||||
{
|
||||
offenderProvince = provinces[i];
|
||||
System.out.println("1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void defenderProvince()
|
||||
{
|
||||
{
|
||||
for (int i = 1; i <= provinceCount; i++)
|
||||
{
|
||||
if (provinces[i].hasClicked() == true)//&& defenderProvince != offenderProvince)
|
||||
{
|
||||
defenderProvince = provinces[i];
|
||||
System.out.println("2");
|
||||
chooser();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void chooser()
|
||||
{
|
||||
Dice_Offender diceOffender = new Dice_Offender();
|
||||
int[] maxDiceOffender = diceOffender.max_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);
|
||||
}
|
||||
|
||||
private void decider(int[] maxDiceOffender, int [] maxDiceDefender)
|
||||
{
|
||||
|
||||
int maxDefender = maxDiceDefender[1];
|
||||
int maxOffender = maxDiceOffender[2];
|
||||
if (maxOffender>maxDefender && defenderProvince.getEntityCount()>1)
|
||||
{
|
||||
int EntitiesOffender = offenderProvince.getEntityCount();
|
||||
int EntitiesDefender = defenderProvince.getEntityCount();
|
||||
defenderProvince.setEntityCount(EntitiesDefender - 1);
|
||||
}
|
||||
|
||||
if (maxOffender<maxDefender && offenderProvince.getEntityCount()>1)
|
||||
{
|
||||
int EntitiesOffender = offenderProvince.getEntityCount();
|
||||
int EntitiesDefender = defenderProvince.getEntityCount();
|
||||
offenderProvince.setEntityCount(EntitiesOffender - 1);
|
||||
}
|
||||
|
||||
if (maxOffender>maxDefender && defenderProvince.getEntityCount()==1)
|
||||
{
|
||||
defenderProvince.setOwner(offenderProvince.getOwner());
|
||||
defenderProvince.setEntityCount(0);
|
||||
}
|
||||
|
||||
if (maxOffender>maxDefender && offenderProvince.getEntityCount()==1)
|
||||
{
|
||||
offenderProvince.setOwner(defenderProvince.getOwner());
|
||||
offenderProvince.setEntityCount(0);
|
||||
}
|
||||
System.out.println("3");
|
||||
offenderProvince = null;
|
||||
defenderProvince = null;
|
||||
}
|
||||
}
|
||||
|
||||
//Ein <3 für Felix (von Aaron)(geschrieben von Samuel)(aber Aaron wollte das ich des schreib)
|
Loading…
Reference in New Issue