This commit is contained in:
Kai S. K. Engelbart 2019-04-10 08:41:56 +02:00
parent 7ae28ce948
commit 349855a4af
2 changed files with 35 additions and 35 deletions

View File

@ -66,7 +66,6 @@ public class Board extends JPanel {
case MouseEvent.BUTTON3:
flagTile(n, m);
}
if (gameState != GameState.ACTIVE) repaint();
}
});
}
@ -80,7 +79,7 @@ public class Board extends JPanel {
setPreferredSize(new Dimension(config.width * tileSize, config.height * tileSize));
gameState = GameState.ACTIVE;
this.mines = config.mines;
mines = config.mines;
activeTiles = boardWidth * boardHeight;
flaggedTiles = 0;
@ -97,18 +96,6 @@ public class Board extends JPanel {
init(initialConfig);
}
public void registerGameListener(GameListener listener) {
listeners.add(listener);
}
private void notifyGameStateEvent(GameStateEvent evt) {
listeners.forEach(listener -> listener.onGameStateEvent(evt));
}
private void notifyFlaggedTilesEvent(FlaggedTilesEvent evt) {
listeners.forEach(listener -> listener.onFlaggedTilesEvent(evt));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
@ -155,6 +142,18 @@ public class Board extends JPanel {
}
}
public void registerGameListener(GameListener listener) {
listeners.add(listener);
}
private void notifyGameStateEvent(GameStateEvent evt) {
listeners.forEach(listener -> listener.onGameStateEvent(evt));
}
private void notifyFlaggedTilesEvent(FlaggedTilesEvent evt) {
listeners.forEach(listener -> listener.onFlaggedTilesEvent(evt));
}
private void repaintTile(int n, int m) {
repaint(n * tileSize, m * tileSize, (n + 1) * tileSize, (n + 1) * tileSize);
}

View File

@ -39,47 +39,48 @@ public class CustomDialog extends JDialog {
getContentPane().add(mcontentPanel, BorderLayout.CENTER);
mcontentPanel.setLayout(new GridLayout(0, 3, 0, 0));
{
JLabel lblBoardWidth = new JLabel("Board Width:");
lblBoardWidth.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblBoardWidth);
JLabel lblBoardWidthText = new JLabel("Board Width:");
lblBoardWidthText.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblBoardWidthText);
}
JLabel lblBoardWidth = new JLabel("");
lblBoardWidth.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblBoardWidth);
JSlider sliderBoardWidth = new JSlider();
sliderBoardWidth.addChangeListener((evt) -> lblBoardWidth.setText(String.valueOf(sliderBoardWidth.getValue())));
sliderBoardWidth.setValue(16);
sliderBoardWidth.setMinimum(2);
sliderBoardWidth.setMaximum(30);
mcontentPanel.add(sliderBoardWidth);
{
JLabel label = new JLabel("");
mcontentPanel.add(label);
}
{
JLabel lblBoardHeight = new JLabel("Board Height:");
lblBoardHeight.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblBoardHeight);
JLabel lblBoardHeightText = new JLabel("Board Height:");
lblBoardHeightText.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblBoardHeightText);
}
JLabel lblBoardHeight = new JLabel("");
lblBoardHeight.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblBoardHeight);
JSlider sliderBoardHeight = new JSlider();
sliderBoardHeight
.addChangeListener((evt) -> lblBoardHeight.setText(String.valueOf(sliderBoardHeight.getValue())));
sliderBoardHeight.setValue(16);
sliderBoardHeight.setMaximum(30);
sliderBoardHeight.setMinimum(2);
mcontentPanel.add(sliderBoardHeight);
{
JLabel label = new JLabel("");
mcontentPanel.add(label);
}
{
JLabel lblNumberOfMines = new JLabel("Number of Mines:");
lblNumberOfMines.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblNumberOfMines);
JLabel lblNumberOfMinesText = new JLabel("Number of Mines:");
lblNumberOfMinesText.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblNumberOfMinesText);
}
JLabel lblNumMines = new JLabel("");
lblNumMines.setFont(new Font("Tahoma", Font.PLAIN, 14));
mcontentPanel.add(lblNumMines);
JSlider sliderNumMines = new JSlider();
sliderNumMines.addChangeListener((evt) -> lblNumMines.setText(String.valueOf(sliderNumMines.getValue())));
sliderNumMines.setValue(16);
sliderNumMines.setMinimum(2);
sliderNumMines.setMaximum(200);
mcontentPanel.add(sliderNumMines);
{
JLabel label = new JLabel("");
mcontentPanel.add(label);
}
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));