package edu.ups.gamedev.game;
import java.net.InetAddress;
import javax.swing.JFrame;
import com.jmex.editors.swing.settings.GameSettingsPanel;
import com.jmex.game.StandardGame;
import com.jmex.game.state.GameStateManager;
import edu.ups.gamedev.net.NetworkCommon;
import edu.ups.gamedev.ui.NetworkPanel;
public class TankGame {
public static StandardGame GAME;
public static TankGameState GAMESTATE;
public static PhysicsGameState PHYSICS;
public static NetworkCommon NETWORK;
private static boolean runServer = false; // run a server if true, run a client if false
private static InetAddress serverAddress;
public static void main(String[] args) throws Exception {
askRunServer();
StandardGame game = new StandardGame("Tank Game");
GAME = game;
boolean runGame = GameSettingsPanel.prompt(game.getSettings());
// only start the game if we actually accept the settings
if (runGame) {
game.start();
PhysicsGameState physics = new PhysicsGameState(120f, 2.2f);
PHYSICS = physics;
physics.getPhysicsSpace().setAutoRestThreshold(.5f);
GameStateManager.getInstance().attachChild(physics);
TankGameState tankGameState = new TankGameState(runServer, serverAddress);
GAMESTATE = tankGameState;
tankGameState.init();
NETWORK = tankGameState.getNetwork();
GameStateManager.getInstance().attachChild(tankGameState);
tankGameState.setActive(true);
physics.setActive(true);
} else {
game.shutdown();
}
}
/**
* Queries the user for whether or not to run in server mode.
*/
private static void askRunServer() {
NetworkPanel netPan;
netPan = new NetworkPanel();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(netPan);
frame.pack();
frame.setVisible(true);
runServer = netPan.isServer();
serverAddress = netPan.getServerAddress();
// make sure this thread goes away
frame.dispose();
}
}