Exemplo n.º 1
0
 /* The following two methods activate the scoring buttons. */
 protected void clickScoreCell(int code, Match m) {
   Player p = m.getCurrentPlayer();
   int gameNum = m.getGameNum();
   Evaluator eval = new Evaluator();
   eval.evaluate(db, code, p, gameNum);
   show_scoreSheet(p, gameNum);
   disable_AllCells();
   rollButton.setEnabled(false);
   nextPlayerJButton.setEnabled(true);
 }
Exemplo n.º 2
0
  // Constructor for  the GUI
  public GuiYahtzee(final Match m, boolean cheat) {
    JButton quit = new JButton("Final Scores, then Quit");
    JLabel title = new JLabel("Yahtzee World!");
    title.setFont(new Font("SansSerif", Font.ITALIC, 24));
    final JFrame f = new JFrame();
    JPanel cont = new JPanel();
    cont.setLayout(new BorderLayout());

    // add the three JPanels
    gbLayout = new GridBagLayout();
    scores.setLayout(gbLayout);

    // Create the rows of category JButtons and fields
    for (int row = CellCodes.ONES; row <= CellCodes.CHANCE; row++) {
      oneRow(butLabels[row], row, m);
    }

    // Make the totals displays
    make_totals_rows("Upper Section Bonus", CellCodes.USBONUS);
    make_totals_rows("Total Upper Section", CellCodes.TOTALUS);
    make_totals_rows("Total Lower Section", CellCodes.TOTALLS);
    make_totals_rows("Yahtzee Bonus", CellCodes.YAHBONUS);
    make_totals_rows("Grand Total", CellCodes.GRANDTOTAL);

    // Make the dice and JCheckBoxes
    make_dice_and_JCheckBoxes(db, cheat);

    rollButton.addActionListener(
        new ActionListener() {
          // This method is called when the user clicks the JButton
          public void actionPerformed(ActionEvent e) {
            enable_JButtons(m.getCurrentPlayer(), m.getGameNum());
            doARoll(db, m, rollButton);
          }
        });

    if (m.getNumPlayers() == 1) nextPlayerJButton.setText("Next Go");
    nextPlayerJButton.setEnabled(false);
    nextPlayerJButton.addActionListener(
        new ActionListener() {
          // This method is called when the user clicks the JButton
          public void actionPerformed(ActionEvent e) {
            m.nextPlayer();
            nextPlayerJButton.setEnabled(false);
            if (m.getGameNum() == Match.MAXGAMES) {
              nextPlayerJLabel.setText("All games played!");
              nextPlayerJLabel.setBackground(Color.black);
              nextPlayerJLabel.setBackground(Color.white);
              rollButton.setEnabled(false);
            } else {
              rollButton.setEnabled(true);
              nextPlayerJLabel.setText(
                  "Player: "
                      + m.getCurrentPlayer().getName()
                      + " Game: "
                      + (m.getGameNum() + 1)
                      + " Round: "
                      + (m.getRoundNum() + 1));
              show_scoreSheet(m.getCurrentPlayer(), m.getGameNum());
              rollButton.setText("Roll the Dice!");
              reset_board();
            }
          }
        });

    nextPlayerJLabel.setText(
        "Player: "
            + m.getCurrentPlayer().getName()
            + " Game: "
            + (m.getGameNum() + 1)
            + " Round: "
            + (m.getRoundNum() + 1));
    quit.addActionListener(
        new ActionListener() {
          // This method is called when the user clicks the JButton
          public void actionPerformed(ActionEvent e) {
            final_scores(m);
            f.dispose();
          }
        });

    cont.add(quit, "North");
    cont.add(title, "Center");
    cont.add(scores, "South");
    f.add(cont, "North");
    f.add(diceSet, "Center");
    f.add(nextPlayerJLabel, "South");
    f.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
    f.setResizable(false);
  }