Cleanup
This commit is contained in:
parent
04643dd702
commit
e9605a51ab
@ -66,7 +66,6 @@ public class Board extends JPanel {
|
|||||||
case MouseEvent.BUTTON3:
|
case MouseEvent.BUTTON3:
|
||||||
flagTile(n, m);
|
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));
|
setPreferredSize(new Dimension(config.width * tileSize, config.height * tileSize));
|
||||||
|
|
||||||
gameState = GameState.ACTIVE;
|
gameState = GameState.ACTIVE;
|
||||||
this.mines = config.mines;
|
mines = config.mines;
|
||||||
activeTiles = boardWidth * boardHeight;
|
activeTiles = boardWidth * boardHeight;
|
||||||
flaggedTiles = 0;
|
flaggedTiles = 0;
|
||||||
|
|
||||||
@ -97,18 +96,6 @@ public class Board extends JPanel {
|
|||||||
init(initialConfig);
|
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
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(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) {
|
private void repaintTile(int n, int m) {
|
||||||
repaint(n * tileSize, m * tileSize, (n + 1) * tileSize, (n + 1) * tileSize);
|
repaint(n * tileSize, m * tileSize, (n + 1) * tileSize, (n + 1) * tileSize);
|
||||||
}
|
}
|
||||||
|
@ -39,47 +39,48 @@ public class CustomDialog extends JDialog {
|
|||||||
getContentPane().add(mcontentPanel, BorderLayout.CENTER);
|
getContentPane().add(mcontentPanel, BorderLayout.CENTER);
|
||||||
mcontentPanel.setLayout(new GridLayout(0, 3, 0, 0));
|
mcontentPanel.setLayout(new GridLayout(0, 3, 0, 0));
|
||||||
{
|
{
|
||||||
JLabel lblBoardWidth = new JLabel("Board Width:");
|
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));
|
lblBoardWidth.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
||||||
mcontentPanel.add(lblBoardWidth);
|
mcontentPanel.add(lblBoardWidth);
|
||||||
}
|
|
||||||
JSlider sliderBoardWidth = new JSlider();
|
JSlider sliderBoardWidth = new JSlider();
|
||||||
|
sliderBoardWidth.addChangeListener((evt) -> lblBoardWidth.setText(String.valueOf(sliderBoardWidth.getValue())));
|
||||||
sliderBoardWidth.setValue(16);
|
sliderBoardWidth.setValue(16);
|
||||||
sliderBoardWidth.setMinimum(2);
|
sliderBoardWidth.setMinimum(2);
|
||||||
sliderBoardWidth.setMaximum(30);
|
sliderBoardWidth.setMaximum(30);
|
||||||
mcontentPanel.add(sliderBoardWidth);
|
mcontentPanel.add(sliderBoardWidth);
|
||||||
{
|
{
|
||||||
JLabel label = new JLabel("");
|
JLabel lblBoardHeightText = new JLabel("Board Height:");
|
||||||
mcontentPanel.add(label);
|
lblBoardHeightText.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
||||||
|
mcontentPanel.add(lblBoardHeightText);
|
||||||
}
|
}
|
||||||
{
|
JLabel lblBoardHeight = new JLabel("");
|
||||||
JLabel lblBoardHeight = new JLabel("Board Height:");
|
|
||||||
lblBoardHeight.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
lblBoardHeight.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
||||||
mcontentPanel.add(lblBoardHeight);
|
mcontentPanel.add(lblBoardHeight);
|
||||||
}
|
|
||||||
JSlider sliderBoardHeight = new JSlider();
|
JSlider sliderBoardHeight = new JSlider();
|
||||||
|
sliderBoardHeight
|
||||||
|
.addChangeListener((evt) -> lblBoardHeight.setText(String.valueOf(sliderBoardHeight.getValue())));
|
||||||
sliderBoardHeight.setValue(16);
|
sliderBoardHeight.setValue(16);
|
||||||
sliderBoardHeight.setMaximum(30);
|
sliderBoardHeight.setMaximum(30);
|
||||||
sliderBoardHeight.setMinimum(2);
|
sliderBoardHeight.setMinimum(2);
|
||||||
mcontentPanel.add(sliderBoardHeight);
|
mcontentPanel.add(sliderBoardHeight);
|
||||||
{
|
{
|
||||||
JLabel label = new JLabel("");
|
JLabel lblNumberOfMinesText = new JLabel("Number of Mines:");
|
||||||
mcontentPanel.add(label);
|
lblNumberOfMinesText.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
||||||
}
|
mcontentPanel.add(lblNumberOfMinesText);
|
||||||
{
|
|
||||||
JLabel lblNumberOfMines = new JLabel("Number of Mines:");
|
|
||||||
lblNumberOfMines.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
|
||||||
mcontentPanel.add(lblNumberOfMines);
|
|
||||||
}
|
}
|
||||||
|
JLabel lblNumMines = new JLabel("");
|
||||||
|
lblNumMines.setFont(new Font("Tahoma", Font.PLAIN, 14));
|
||||||
|
mcontentPanel.add(lblNumMines);
|
||||||
JSlider sliderNumMines = new JSlider();
|
JSlider sliderNumMines = new JSlider();
|
||||||
|
sliderNumMines.addChangeListener((evt) -> lblNumMines.setText(String.valueOf(sliderNumMines.getValue())));
|
||||||
sliderNumMines.setValue(16);
|
sliderNumMines.setValue(16);
|
||||||
sliderNumMines.setMinimum(2);
|
sliderNumMines.setMinimum(2);
|
||||||
sliderNumMines.setMaximum(200);
|
sliderNumMines.setMaximum(200);
|
||||||
mcontentPanel.add(sliderNumMines);
|
mcontentPanel.add(sliderNumMines);
|
||||||
{
|
|
||||||
JLabel label = new JLabel("");
|
|
||||||
mcontentPanel.add(label);
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
JPanel buttonPane = new JPanel();
|
JPanel buttonPane = new JPanel();
|
||||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user