Esempio n. 1
0
 public synchronized void spectate(
     HeadsUpHand hand, HeadsUpPokerGame game, int streetIn, String message) {
   clearMessages();
   addMessage(message);
   // Output board
   hand.printBoard(game, streetIn, game.handNumber, this);
   // Output hand and player stats
   addMessage(this.toString(game));
   send();
   clearMessages();
 }
Esempio n. 2
0
  // This method gets called from a method in the Hand object (startStreet())
  // In that method, each player is looped through to act();
  public synchronized int act(
      int minimumBet, int pot, HeadsUpHand hand, HeadsUpPokerGame game, int streetIn) {

    boolean isCorrect = false;
    String action;
    int betSize = minimumBet;
    if (!this.folded && !this.isAllIn) {
      while (!isCorrect) {
        // Output board
        hand.printBoard(game, streetIn, game.handNumber, this);
        // Output hand and player stats
        addMessage(this.toString(game));
        addMessage("Bet/Check/Call/Fold");
        send();
        clearMessages();
        action = receive();
        // Checks what action user inputs
        if (action.equalsIgnoreCase("Bet")) {
          while (true) {
            // Output board
            hand.printBoard(game, streetIn, game.handNumber, this);
            // Output hand and player stats
            addMessage(this.toString(game));
            try {
              addMessage("Size");
              send();
              clearMessages();
              // Requires exception?
              try {
                betSize = Integer.parseInt(receive());
              } catch (NumberFormatException e) {
                e.printStackTrace();
              }

              // For headsup this is fine since there isn't a scenario where your betsize is
              // larger than how much the other player has and also less that what you have
              if (betSize > game.players.get(otherPlayerID).getMoney()) {
                // Only allow player to bet how much other play has
                betSize = game.players.get(otherPlayerID).getMoney();
                // Any additional bet is total (don't have to remember previous bet)
                this.spendMoney(betSize - streetMoney);
                hand.addToPot(betSize - streetMoney);
                // Total streetmoney becomes betsize
                streetMoney = betSize;
                isCorrect = true;
                game.players.get(otherPlayerID).addMessage(name + " puts you all in");
                // Increase all in counter so that
                // when other player calls further actions are skipped
                hand.increaseAllInCounter();
              } else if (money <= betSize) {
                // If betsize is greater than money, player is all in
                betSize = money;
                this.spendMoney(betSize);
                hand.addToPot(betSize);
                streetMoney = betSize;
                isAllIn = true;
                hand.increaseAllInCounter();
                isCorrect = true;
                if (streetIn != 12) {
                  game.players.get(otherPlayerID).addMessage(name + " is all in");
                }
              } else if (betSize < 2 * minimumBet || betSize == 0) {
                addMessage("Illegal bet size");
                // Reset betsize to what was previously bet (miniumum bet)
                betSize = minimumBet;
              } else {
                // Any additional bet is total (don't have to remember previous bet)
                this.spendMoney(betSize - streetMoney);
                hand.addToPot(betSize - streetMoney);
                // Total streetmoney becomes betsize
                streetMoney = betSize;
                isCorrect = true;
                game.players.get(otherPlayerID).addMessage(name + " bet " + betSize);
              }
              break;
            } catch (InputMismatchException e) {
              addMessage("Not a number");
              in.next();
              continue;
            }
          }
        }
        // we need a way for BB to check b/c minbet is still > 0 for him
        else if (action.equalsIgnoreCase("Check")) {
          if (minimumBet - streetMoney > 0) {
            addMessage("You cannot check when the pot is raised");
          } else {
            isCorrect = true;
            betSize = 0;
            game.players.get(otherPlayerID).addMessage(name + " checked");
          }
        } else if (action.equalsIgnoreCase("Call")) {
          if (minimumBet == 0 || minimumBet - streetMoney == 0) {
            addMessage("You cannot call when there is no bet");
          } else if (money <= minimumBet) {
            betSize = money;
            this.spendMoney(betSize);
            hand.addToPot(betSize);
            isAllIn = true;
            // If you call all in then hand must end
            // Add 1 to AllInCounter in order to skip further actions == players.size() in Hand
            // class
            // Betting all in is different since other player still has to act
            hand.increaseAllInCounter();
            isCorrect = true;
            if (streetIn != 12) {
              game.players.get(otherPlayerID).addMessage(name + " is all in");
            }
          } else {
            this.spendMoney(minimumBet - streetMoney);
            hand.addToPot(minimumBet - streetMoney);
            isCorrect = true;
            betSize = minimumBet;
            game.players.get(otherPlayerID).addMessage(name + " called " + betSize);
          }
        } else if (action.equalsIgnoreCase("Fold")) {
          this.fold();
          isCorrect = true;
          betSize = 0;
        } else {
          addMessage("Incorrect action, please try again");
        }
      }
    } else {
      betSize = 0;
    }
    return betSize;
  }