예제 #1
0
  /** Called when one of the tiles is clicked */
  @Override
  public void actionPerformed(ActionEvent e) {

    JButton clickedButton = (JButton) e.getSource();

    if (clickedButton.getText().equals("Start New Game")) {

      startNewGame();

    } else if (clickedButton.getText().equals("Enter Manual Setup")) {

      game.setManualSetup(!game.getManualSetup());
      gui.setSetupText("Exit Manual Setup");

    } else if (clickedButton.getText().equals("Exit Manual Setup")) {

      game.setManualSetup(!game.getManualSetup());
      gui.setSetupText("Enter Manual Setup");

    } else if (clickedButton.getText().equals("Change Tile Colors")) {

      gui.editColors();

    } else {

      // Tile was clicked

      int row = clickedButton.getName().charAt(0) - '0';
      int col = clickedButton.getName().charAt(1) - '0';

      try {
        game.toggle(row, col);
        gui.updateUI(game.getLights());
        gui.setMoveLabel("Moves: " + game.getMoveCount());
      } catch (IllegalArgumentException e1) {

      }
      if (game.isWon()) {
        gui.displayWinMessage();
      }
    }
  }