/* (non-Javadoc)
* @see com.mlarktar.spacewar.SWCommand#init()
*/
public void init() {
NewGame ngf = app.ngf;
Rectangle bounds = space.getBounds();
int unity = bounds.height / 10;
int unitx = bounds.width / 10;
// Add the two ships to space
if (ngf.getShip1Pilot() == NewGame.PILOTHUMAN) {
ship1 = new Ship(unitx * 2, unity * 2, space);
} else {
ship1 = new ShipAI(unitx * 2, unity * 2, space);
}
if (ngf.getShip2Pilot() == NewGame.PILOTHUMAN) {
ship2 =
new Ship(
bounds.width - unitx * 2,
bounds.height - unity * 2,
space);
} else {
ship2 =
new ShipAI(
bounds.width - unitx * 2,
bounds.height - unity * 2,
space);
}
ship1.setEnemy(ship2);
ship2.setEnemy(ship1);
ship1.setSounds(SoundServer.getSoundEvents());
ship2.setSounds(SoundServer.getSoundEvents());
ship1.setRepresentation(new DeffensiveRepresentation());
ship2.setRepresentation(new OffensiveRepresentation());
space.addSpaceItem(ship1);
space.addSpaceItem(ship2);
// Add observers that show ships energy levels
so1 = new ShipObserver(unitx, unity, ship1);
so2 = new ShipObserver(unitx, bounds.height - unity, ship2);
space.addSpaceItem(so1);
space.addSpaceItem(so2);
// Send all keystrokes to the KeyInterpreter object
if (ngf.getShip2Pilot() == ngf.getShip1Pilot()) {
if (ngf.getShip2Pilot() == NewGame.PILOTHUMAN) {
controller = new KeyInterpreter(ship1, ship2);
} else {
controller = null;
}
} else {
if (ngf.getShip1Pilot() == NewGame.PILOTHUMAN) {
controller = new KeyInterpreter(ship1, new NullShip());
} else {
controller = new KeyInterpreter(new NullShip(), ship2);
}
}
// Adds a planet in the middle of the screen
if (ngf.getUsePlanet() || ngf.getUseGravity()) {
Planet planet =
new Planet(
(int) bounds.getCenterX(),
(int) bounds.getCenterY(),
ngf.getUsePlanet());
space.addSpaceItem(planet, ngf.getUseGravity());
}
space.fillWithStars();
keyListener = controller;