Browse Source

Refactore MinesweeperGame

feature_Minesweeper_Playfield
kfkama 3 years ago
parent
commit
00b6ab308c
  1. 21
      src/test/java/Minesweeper/MinesweeperGame.java

21
src/test/java/Minesweeper/MinesweeperGame.java

@ -6,17 +6,24 @@ import javax.swing.JPanel;
public class MinesweeperGame extends 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) { public MinesweeperGame(int _playfieldSize) {
this.setSize(600, 600);
this.setSize(WIDTH, HEIGTH);
playfieldSize = _playfieldSize;
setLayout(null); 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(); JButton b = new JButton();
b.setBounds(j * 40, i * 40, 40, 40);
b.setBounds(j * CELLSIZE, i * CELLSIZE, CELLSIZE, CELLSIZE);
add(b); add(b);
} }
} }
@ -27,7 +34,7 @@ public class MinesweeperGame extends JPanel {
MinesweeperGame ttt = new MinesweeperGame(8); MinesweeperGame ttt = new MinesweeperGame(8);
f.add(ttt); f.add(ttt);
f.setSize(600, 600);
f.setSize(WIDTH, HEIGTH);
f.setLayout(null); f.setLayout(null);
f.setVisible(true); f.setVisible(true);

Loading…
Cancel
Save