コード例 #1
0
ファイル: Table.java プロジェクト: mgp/blackjack-analyst
 /**
  * Attempts to remove the given player from the table. For this method to succeed and return
  * {@code true}, the player must be at the table already.
  *
  * @param player the player to remove from the table
  * @return {@code true} if the player is removed from the table, {@code false} otherwise
  */
 public boolean removePlayer(Player player) {
   if (players.remove(player)) {
     player.table = null;
     player.bets = null;
     player.betsReadOnly = null;
     // notify strategy
     player.strategy.leftTable(this);
     // notify observers
     player.playerLeaves(this);
     playerLeaves(player);
     return true;
   }
   return false;
 }
コード例 #2
0
ファイル: Table.java プロジェクト: mgp/blackjack-analyst
 /**
  * Attempts to add the given player to the table. For this method to succeed and return {@code
  * true}, the table must have room for the player and the player must not be at a table already.
  * Otherwise, this method returns {@code false}.
  *
  * @param player the player to add to the table
  * @return {@code true} if the player is added to the table, {@code false} otherwise
  */
 public boolean addPlayer(Player player) {
   if (hasRoom() && (player.table == null)) {
     players.add(player);
     player.table = this;
     player.bets = new ArrayList<PlayerHand>();
     player.betsReadOnly = Collections.unmodifiableList(player.bets);
     // notify strategy
     player.strategy.joinedTable(this);
     // notify observers
     player.playerJoins(this);
     playerJoins(player);
     return true;
   }
   return false;
 }
コード例 #3
0
ファイル: RoomView.java プロジェクト: anujmnit71/oops_code
 private void raiseToActionPerformed() {
   if (Integer.parseInt(raise.getText()) < me.table().toCall() + 2 * me.table().small()
       && Integer.parseInt(raise.getText()) < me.chips())
     raise.setText(
         Integer.toString(
             me.table().toCall() + 2 * me.table().small() > me.chips()
                 ? me.chips()
                 : me.table().toCall() + 2 * me.table().small()));
   else out.println("raiseTo " + raise.getText());
 }
コード例 #4
0
ファイル: RoomView.java プロジェクト: anujmnit71/oops_code
  private String status(Player p) {

    if (p.table() == null) return " ";
    else if (!p.table().inHand().contains(p)) {

      if (p.table().dealTo().contains(p) && p.table().inHand().size() > 0) return "Folded";
      else if (!p.table().in().contains(p)) return "Sitting Out";
      else return " ";

    } else if (p.chips() == 0) return "All In";
    else if (p.table().hasToCall().contains(this) && !p.action().startsWith("Posted")) return " ";
    else return p.action();
  }
コード例 #5
0
ファイル: RoomView.java プロジェクト: anujmnit71/oops_code
 private void leaveTableActionPerformed() {
   if (me.turn())
     players.get(me.table().seats().indexOf(me)).get("name").setBackground(pot.getBackground());
   out.println("leaveTable");
 }
コード例 #6
0
ファイル: RoomView.java プロジェクト: anujmnit71/oops_code
  public void update(Room r) {

    if (room == null) model = new String[r.tables().size()];
    room = r;
    me = name.isEnabled() ? null : r.players().get(name.getText());
    for (int i = 0; i < model.length; i++)
      model[i] = "Table " + i + " (" + room.tables().get(i).size() + ")";
    tables.setModel(new javax.swing.DefaultComboBoxModel(model));
    if (me == null) return;

    join.setEnabled(me.table() == null);
    leaveTable.setEnabled(me.table() != null);
    sitOut.setEnabled(me.table() != null);
    say.setEnabled(me.table() != null);
    raise.setEnabled(me.table() != null);
    fold.setEnabled(me.turn());
    call.setEnabled(me.turn());
    raiseTo.setEnabled(me.turn() && me.chips() > me.table().toCall());
    chat.setText(room.chat()); // room vs table chat

    if (me.table() == null) {

      for (int i = 0; i < 5; i++) board.get(i).setIcon(null);
      pot.setText(" ");
      potNow.setText(" ");
      inPot.setText(" ");
      toCall.setText(" ");
      raise.setText(" ");

      for (int i = 0; i < 9; i++) {

        players.get(i).get("name").setText(" ");
        players.get(i).get("chips").setText(" ");
        players.get(i).get("toPot").setText(" ");
        players.get(i).get("card0").setIcon(null);
        players.get(i).get("card1").setIcon(null);
        players.get(i).get("status").setText(" ");
      }

      return;
    }

    tables.setSelectedIndex(room.tables().indexOf(me.table()));
    pot.setText(Integer.toString(me.table().pot()));
    potNow.setText(Integer.toString(me.table().pot() + me.table().toPot()));
    for (int i = 0; i < me.table().board().size(); i++)
      board
          .get(i)
          .setIcon(
              new ImageIcon(
                  getClass().getResource("/cards_gif/" + me.table().board().get(i).image())));
    for (int i = me.table().board().size(); i < 5; i++) board.get(i).setIcon(null);

    sitOut.setSelected(!me.table().in().contains(me));
    sitOut.setEnabled(me.chips() > 0);
    inPot.setText(Integer.toString(me.inPot()));
    toCall.setText(Integer.toString(me.table().toCall() - me.toPot()));
    raise.setText(
        Integer.toString(
            me.table().toCall() + 2 * me.table().small() > me.chips()
                ? me.chips()
                : me.table().toCall() + 2 * me.table().small()));

    for (int i = 0; i < 9; i++) {

      if (me.table().seats().get(i) == null) {

        players.get(i).get("name").setText("empty");
        players.get(i).get("chips").setText(" ");
        players.get(i).get("toPot").setText(" ");
        players.get(i).get("card0").setIcon(null);
        players.get(i).get("card1").setIcon(null);
        players.get(i).get("status").setText(" ");

      } else {

        players.get(i).get("name").setText(me.table().seats().get(i).name());
        players.get(i).get("chips").setText(Integer.toString(me.table().seats().get(i).chips()));
        players.get(i).get("toPot").setText(Integer.toString(me.table().seats().get(i).toPot()));

        if (me.table()
            .inHand()
            .contains(
                me.table()
                    .seats()
                    .get(i))) { // contains! and status computation at gui! make function

          if (me.table().ranked() && me.table().mustShow().contains(me.table().seats().get(i))) {

            players
                .get(i)
                .get("card0")
                .setIcon(
                    new ImageIcon(
                        getClass()
                            .getResource(
                                "/cards_gif/" + me.table().seats().get(i).cards().get(0).image())));
            players
                .get(i)
                .get("card1")
                .setIcon(
                    new ImageIcon(
                        getClass()
                            .getResource(
                                "/cards_gif/" + me.table().seats().get(i).cards().get(1).image())));
            players
                .get(i)
                .get("status")
                .setText(me.table().seats().get(i).hand().type().toString());
            if (me.table().winners().contains(me.table().seats().get(i)))
              players
                  .get(i)
                  .get("toPot")
                  .setText(
                      "wins "
                          + (me.table().seats().get(i).chips() == 0
                                  && me.table().seats().get(i).sidePot() != me.table().pot()
                              ? "side pot"
                              : "main pot"));

          } else if (i != me.table().seats().indexOf(me)) {

            players.get(i).get("card0").setIcon(back);
            players.get(i).get("card1").setIcon(back);
            players
                .get(i)
                .get("status")
                .setText(me.table().ranked() ? "Mucks" : status(me.table().seats().get(i)));

          } else {

            players
                .get(i)
                .get("card0")
                .setIcon(
                    new ImageIcon(
                        getClass().getResource("/cards_gif/" + me.cards().get(0).image())));
            players
                .get(i)
                .get("card1")
                .setIcon(
                    new ImageIcon(
                        getClass().getResource("/cards_gif/" + me.cards().get(1).image())));
            players
                .get(i)
                .get("status")
                .setText(me.table().board().size() > 2 ? me.hand().type().toString() : status(me));
          }

        } else {

          players.get(i).get("card0").setIcon(null);
          players.get(i).get("card1").setIcon(null);
          players.get(i).get("status").setText(status(me.table().seats().get(i)));
        }

        if (me.table().seats().get(i).turn()) players.get(i).get("name").setBackground(Color.white);
        else players.get(i).get("name").setBackground(pot.getBackground());
      }
    }

    players
        .get(me.table().dealer())
        .get("name")
        .setText(players.get(me.table().dealer()).get("name").getText() + " (D)");
  }