Exemple #1
0
  @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!");
  }
Exemple #2
0
 public void closeNetworking() {
   for (FixedTimer timer : timers) timer.stop();
   timers.clear();
   if (Global.connectingSocket != null) {
     try {
       Global.connectingSocket.close();
     } catch (IOException ex) {
     }
   }
   closeClient(mainServer);
   closeClient(bulletStream);
   closeClient(powerStream);
   closeClient(turretStream);
   closeClient(powerRemover);
   closeClient(chatLog);
   closeClient(fadeLog);
   closeClient(serverTime);
   if (playerByteStreams != null) {
     for (int i = 0; i < playerByteStreams.length; ++i) {
       closeClient(playerByteStreams[i]);
     }
   }
 }
Exemple #3
0
 void turnOnEndGameReceiver() {
   FixedTimer.schedule(
       new Runnable() {
         public void run() {
           try {
             String message = mainServer.readLine();
             if (message.startsWith("END:")) {
               endTheGame(message.substring(4));
             }
           } catch (IOException ex) {
             System.err.println("Error getting end of game message from server: " + ex);
             Global.onException();
           }
         }
       });
 }