public static void main(String[] args) { Global.debugging = true; // make frame final JFrame frame = new JFrame("Test Client Game"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // make game ClientGame game = null; String[] names = { "Alpha", "Beta", "Charlie", "Delta", "Epsilon", "Foxtrot", "Gamma", "Hurricane" }; int ptr = 0; while (true) { try { game = new ClientGame(names[ptr++], (args.length > 1 ? args[1] : "localhost")); break; } catch (ClientNameException ex) { System.err.println(ex); } catch (IOException ex) { System.err.println("Could not connect to server"); } } // add controls to frame game.getPlayerShip().getControls().setContainer(frame); // add full screen toggle FullScreenToggle.addToggleToGame(frame, game, KeyEvent.VK_F11); // add game to frame frame.add(game); // show frame frame.pack(); frame.setVisible(true); game.startTheGame(); }
@Override protected void performAction(String message) { super.performAction(message); if (Message.serverReady(message)) game.serverReady(Message.getPlayersName(message)); else { int id = Message.getPlayerId(message); if (id != game.localId) controllers[id - 1].performAction(message); } }
/** * Makes the move that is returned by getMove(). If the stonelist returned by getMove is empty as * much stones as possible are traded. * * @param game * @param stones */ @Override public void determineMove(ClientGame game, List<Stone> stones) { List<Stone> stonesplaced = getMove(game.getBoard(), stones); if (stonesplaced.isEmpty()) { List<Stone> toTrade; if (game.getBag() < stones.size()) { toTrade = new ArrayList<Stone>(); for (int i = 0; i < game.getBag(); i++) { toTrade.add(stones.get(i)); } } else { toTrade = stones; } game.getClient().trade(toTrade); List<Stone> toRemove = new ArrayList<Stone>(); toRemove.addAll(toTrade); game.getCurrentPlayer().removeStones(toRemove); } else { game.getClient().place(stonesplaced); List<Stone> toRemove = new ArrayList<Stone>(); toRemove.addAll(stonesplaced); game.getCurrentPlayer().removeStones(toRemove); } }