예제 #1
0
 private void voteForCandidate() {
   try {
     int candidateToVoteFor = in.readByte();
     if (player.getRound() == "first") {
       model.getCandidate(candidateToVoteFor).voteFirst();
       player.addVote(candidateToVoteFor, 1);
     } else if (player.getRound() == "final") {
       model.getCandidate(candidateToVoteFor).voteSecond();
       player.addVote(candidateToVoteFor, 2);
     } else {
       model.getCandidate(candidateToVoteFor).voteStraw();
       player.addVote(candidateToVoteFor, 0);
     }
   } catch (IOException e) {
     removePlayer();
   }
 }
예제 #2
0
  private void returnInfo() {
    try {
      int candidateToBuyFrom = in.readInt();
      Candidate candidate = model.getCandidate(candidateToBuyFrom);
      int ideal = candidate.getIdealPt();
      int random = (int) (Math.random() * 100);
      int signal = (random > ideal) ? 0 : 1;
      player.addInfo(candidateToBuyFrom, signal);
      int[] info = player.getInfo(candidateToBuyFrom);

      int tokens = info[0] + info[1];
      int signals = info[1];

      writeMessage(6, candidateToBuyFrom);
      out.writeInt(tokens);
      out.writeInt(signals);
    } catch (IOException e) {
      removePlayer();
    }
  }