コード例 #1
0
ファイル: Server.java プロジェクト: pg1770/Minesweeper_JAVA
    public void run() {
      try {
        while (((fromClientObject = in.readObject()) != null) && connection.isConnected()) {

          if (fromClientObject.getClass() == String.class) {
            synchronized (players) {
              String playerName = (String) fromClientObject;
              players.addPlayer(ID, playerName, 0);
              broadcast(players);
            }
          }

          if (fromClientObject.getClass() == Integer.class) {
            synchronized (players) {
              int tableSize = (int) fromClientObject;
              players.changeTableSize(ID, tableSize);
              broadcast(players);
            }
          }

          if (fromClientObject.getClass() == ClickEvent.class) {
            ClickEvent click = (ClickEvent) fromClientObject;
            ctrl.receiveClick(click);
          }

          checkToGameStart();
        }
      } catch (Exception e) {
        ctrl.serverError("Client disconnected!");
      } finally {
        try {
          System.out.println(ID);
          synchronized (receiverList) {
            Collection<ReceiverThread> found =
                Collections.synchronizedList(new ArrayList<ReceiverThread>());
            for (ReceiverThread actualReceiver : receiverList) {
              if (actualReceiver.getID() == ID) {
                found.add(actualReceiver);
              }
            }
            receiverList.removeAll(found);
          }
          synchronized (players) {
            players.removePlayer(ID);
          }
          broadcast(players);
          connection.close();
        } catch (IOException e) {
          ctrl.serverError("Error while closing connection!");
        }
      }
    }
コード例 #2
0
ファイル: Server.java プロジェクト: pg1770/Minesweeper_JAVA
 void broadcast(Scores scoreTable) {
   for (ReceiverThread actualThread : receiverList) {
     actualThread.send(scoreTable);
   }
 }
コード例 #3
0
ファイル: Server.java プロジェクト: pg1770/Minesweeper_JAVA
 void broadcast(GameInfo gameInfo) {
   for (ReceiverThread actualThread : receiverList) {
     actualThread.send(gameInfo);
   }
 }
コード例 #4
0
ファイル: Server.java プロジェクト: pg1770/Minesweeper_JAVA
 void broadcast(TimeStamp timeStamp) {
   for (ReceiverThread actualThread : receiverList) {
     actualThread.send(timeStamp);
   }
 }
コード例 #5
0
ファイル: Server.java プロジェクト: pg1770/Minesweeper_JAVA
 void broadcast(PlayersList players) {
   for (ReceiverThread actualThread : receiverList) {
     actualThread.send(players);
   }
 }