void waitForOtherPlayers() throws IOException { Global.log("Waiting for other players to register..."); int n = Integer.parseInt(mainServer.readLine()); playerNames = new String[n]; for (int i = 0; i < n; ++i) { String info = mainServer.readLine(); playerNames[i] = info; } // ping back to server for an OK mainServer.println(); mainServer.flush(); Global.log("List of Players:"); for (int i = 0; i < n; ++i) Global.log("\t" + (i + 1) + ": " + playerNames[i]); // get player ID for (int i = 0; i < n; ++i) { if (name.equals(playerNames[i])) { playerID = i; break; } } Global.log("Player ID: " + (playerID + 1)); }
@Override public void startTheGame() { gameType = ""; try { // receive ping from server gameType = mainServer.readLine(); } catch (IOException ex) { System.err.println("Could not communicate with server: " + ex); Global.onException(); } super.startTheGame(); for (FixedTimer timer : timers) timer.start(); startMarquee(getGameType(), 1000); startMarquee("3"); startMarquee("2"); startMarquee("1"); // receive ping that the game is starting try { // ping back that client is ready mainServer.println(); mainServer.flush(); // wait for if server is ready mainServer.readLine(); } catch (IOException ex) { System.err.println("Could not communicate with server: " + ex); Global.onException(); } turnOnEndGameReceiver(); startMarquee("START!"); }