/** send GameState to Client */
  private void sendGameState() {
    try {

      GameState gameState = dealer.getGameState();
      out.writeObject(gameState);
      out.flush();
      out.reset();

    } catch (IOException e) {
      e.printStackTrace();
      this.finalize();
    }
  }
  /**
   * we need to open a connection to the client and give it a token so we can identify it in the
   * future
   */
  public void initializeCLient() throws IOException {
    log.debug("initializing Client");
    this.out = new ObjectOutputStream(this.socket.getOutputStream());
    try {

      token = dealer.addPlayer(this);

    } catch (MaxPlayerException e) {
      System.out.println(e.getMessage());
      this.finalize();
    }
    log.debug("sending token");
    out.writeObject(token);
    out.flush();
    out.reset();
  }
 /**
  * @throws IOException listen to client input, add the playertoken to the move. hand move to
  *     dealer.
  */
 public void readInput() throws IOException {
   while (true) {
     Object o;
     try {
       o = this.in.readObject();
       try {
         CardContainer move = (CardContainer) o;
         log.debug("recieved new CardContainer");
         move.setToken(this.token);
         this.dealer.newMove(move);
       } catch (ClassCastException e) {
       }
       try {
         StartContainer start = (StartContainer) o;
         log.debug("recieved startContainer");
         dealer.startGame();
       } catch (ClassCastException e) {
       }
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
       System.exit(1);
     }
   }
 }
Пример #4
0
 @Override
 public void updateLabel() {
   super.updateLabel();
 }