From 00b6ab308c03c679c1154db02099f91fe58ddc6e Mon Sep 17 00:00:00 2001 From: kfkama Date: Wed, 16 Feb 2022 16:56:45 +0100 Subject: [PATCH] Refactore MinesweeperGame --- .../java/Minesweeper/MinesweeperGame.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/test/java/Minesweeper/MinesweeperGame.java b/src/test/java/Minesweeper/MinesweeperGame.java index 8285a98..a7764e3 100644 --- a/src/test/java/Minesweeper/MinesweeperGame.java +++ b/src/test/java/Minesweeper/MinesweeperGame.java @@ -6,17 +6,24 @@ import javax.swing.JPanel; public class MinesweeperGame extends JPanel { + private static final long serialVersionUID = 1L; + private static final int WIDTH = 600, HEIGTH = 600; + private static final int CELLSIZE = 40; + private int playfieldSize; + public MinesweeperGame(int _playfieldSize) { - this.setSize(600, 600); + this.setSize(WIDTH, HEIGTH); + playfieldSize = _playfieldSize; setLayout(null); - initPlayfield(_playfieldSize); + + initPlayfield(); } - private void initPlayfield(int _playfieldSize) { - for (int i = 0; i < _playfieldSize; i++) { - for (int j = 0; j < _playfieldSize; j++) { + private void initPlayfield() { + for (int i = 0; i < playfieldSize; i++) { + for (int j = 0; j < playfieldSize; j++) { JButton b = new JButton(); - b.setBounds(j * 40, i * 40, 40, 40); + b.setBounds(j * CELLSIZE, i * CELLSIZE, CELLSIZE, CELLSIZE); add(b); } } @@ -27,7 +34,7 @@ public class MinesweeperGame extends JPanel { MinesweeperGame ttt = new MinesweeperGame(8); f.add(ttt); - f.setSize(600, 600); + f.setSize(WIDTH, HEIGTH); f.setLayout(null); f.setVisible(true);