Пример #1
0
 public void handleIO() {
   waitForGameStart();
   startGame();
   while (true) {
     try {
       char c = (char) in.readByte();
       while (c != '!') {
         c = (char) in.readByte();
       }
       int messageType = in.readByte();
       if (messageType == 5) { // Bought info
         returnInfo();
       } else if (messageType == 7) { // Ended a buy round
         int whichBuyRound = in.readByte();
         waitForNewRound(); // Waits for all players to be done with the round
         setRound(whichBuyRound); // Sets the round in the player's data
         startRound(whichBuyRound); // Sends out a starting round message
       } else if (messageType == 9) {
         voteForCandidate();
         waitForNewRound();
         if (player.getRound() == "straw") {
           startFirstVote();
         } else if (player.getRound() == "first") {
           startSecondBuy();
         } else {
           sendWinner();
           Player clone = new Player(player);
           model.addPlayerToGameObject(clone, gameNum);
           gameNum++;
           if (gameNum < model.getNumGames()) {
             model.getNewGame(gameNum);
             model.resetPlayer(player);
             startGame();
           } else {
             model.writeDataOut();
           }
         }
       } else {
         // Exceptions?
       }
     } catch (IOException e) {
       removePlayer();
       break; // End client
     }
   }
 }