예제 #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);
 }
예제 #2
0
  private void final_scores(Match m) {
    int numPlayers = 0;
    int playerTotal = 0;
    int gameNum = 0, maxGameNum = 0;
    Player p;

    // Create window
    final JFrame f = new JFrame();
    JPanel titles = new JPanel();
    titles.setLayout(new BorderLayout());
    JLabel maintitle = new JLabel("Yahtzee World!");
    maintitle.setFont(new Font("SansSerif", Font.ITALIC, 24));
    JLabel instr = new JLabel("Final Scores (total of game scores).");
    instr.setFont(new Font("SansSerif", Font.PLAIN, 16));
    titles.add(maintitle, "North");
    titles.add(instr, "South");

    JPanel names = new JPanel();
    JLabel l[] = new JLabel[Match.MAXPLAYERS];
    final JTextField t[] = new JTextField[Match.MAXPLAYERS];

    numPlayers = m.getNumPlayers();
    names.setLayout(new GridLayout(numPlayers, 2));
    for (int playerNum = 0; playerNum < numPlayers; playerNum++) {
      p = m.getPlayer(playerNum);
      playerTotal = 0;
      l[playerNum] = new JLabel(p.getName());
      t[playerNum] = new JTextField(20);
      names.add(l[playerNum]);
      names.add(t[playerNum]);
      maxGameNum = (m.getGameNum() >= Match.MAXGAMES) ? (Match.MAXGAMES - 1) : m.getGameNum();
      for (gameNum = 0; gameNum <= maxGameNum; gameNum++) {
        playerTotal += p.getScoreCell(gameNum, CellCodes.GRANDTOTAL);
      }
      t[playerNum].setText(String.valueOf(playerTotal));
    }

    JButton quit = new JButton("Quit");
    quit.addActionListener(
        new ActionListener() {
          // This method is called when the user clicks the JButton
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    f.add(titles, "North");
    f.add(names, "Center");
    f.add(quit, "South");
    f.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
    f.setResizable(false);
  }
예제 #3
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);
  }