Esempio n. 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();
      }
    }
  }
Esempio n. 2
0
 /** Gets current state of the light board */
 public boolean[][] getLights() {
   return game.getLights();
 }
Esempio n. 3
0
 /** Resets the board into a new game position */
 public void startNewGame() {
   game.reset();
   gui.reset();
 }