this.paint(this.getGraphics());
}
@Override
public void run() {
Planet destPlanet = battle_.getPlanet();
int numAttackShips = battle_.getOrder().getFleetSize();
int numDefendShips = destPlanet.getNumShips();
//String defender = (destPlanet.getOwner()==null)? "Neutral" : destPlanet.getOwner().getName();
// play back the move sequence
List sequence = battle_.getHitSequence();
if (sequence.isEmpty()) {
// reinforced!
GameContext.getMusicMaker().playNote( Instruments.APPLAUSE, 45, 0, 200, 1000 );
GameContext.getMusicMaker().playNote(70, 50, 900);
GameContext.getMusicMaker().playNote(90, 40, 1000);
descriptionLabel_.setText("Planet "+destPlanet.getName()+" has been reinforced.");
}
else {
boolean useSound = GameContext.getUseSound();
Iterator it = sequence.iterator();
if (useSound)
GameContext.getMusicMaker().playNote( Instruments.GUNSHOT, 45, 0, 200, 1000 );
while (it.hasNext()) {
GalacticPlayer p = (GalacticPlayer)it.next();
int total = numAttackShips + numDefendShips;
int time = 1 + BATTLE_SPEED / (1+total);
if (p == battle_.getOrder().getOwner()) {
if (useSound)
GameContext.getMusicMaker().playNote(100, time, 800);
numAttackShips--;
}
else {
if (useSound)
GameContext.getMusicMaker().playNote(80, time, 800);
numDefendShips--;
}
refresh(numAttackShips, numDefendShips);
ThreadUtil.sleep(time);
}
assert(numAttackShips == 0 || numDefendShips == 0):
"numAttackShips="+numAttackShips+" numDefendShips="+numDefendShips;
String winMessage;
if (numAttackShips==0)
winMessage = "Planet "+destPlanet.getName()+" has successfully defended itself.";
else
winMessage = battle_.getOrder().getOwner().getName()+ " has conquered planet "+destPlanet.getName();
descriptionLabel_.setText( "<html>"+ descriptionLabel_.getText()+ "<b>"+ winMessage +"/b></html>");
}
viewer_.showPlanetUnderAttack(battle_.getPlanet(), false); // battle is done