

its easier to test small methods rather than the whole class.
Minesweeper java code#
Lots of your code is complex to read and it would help to create methods to simplify the code - and increase testability. There's certainly more to say, but I'll leave that to the other reviewers. complexity / object orientated design / testability. Now you can define mine fields of arbitrary sizes. While(i = 0 & j >= 0 & i = 0 & j >= 0 & i < Gui.size & j < Gui.size) To review, open the file in an editor that reveals hidden Unicode characters.

Places the bombs/mines randomly in the field Minesweeper.java This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below.
Minesweeper java how to#
Saves the places of the mines and the number of neighbor-mines In this video, I will show you how to set up the JFrame for a minesweeper game developed with Java. The number of bombs should also be specified. Examples: java -jar Minesweeper.jar (recommended) java -jar Minesweeper.jar 20 50. setTitle(A-Minesweeper) setLocation(100, 100) tResizable(false) this. ‘MineSweeper’ class and the ‘main’ method Every time we run the code, the main method will create an object belonging to the class MineSweeper. java -jar Minesweeper.jar BoardWidth NumberofMines If parameters are not specified, will load default. MouseListener author Alexander Apollon Jerabek / import java.awt. Along with the main function, let us also initialize two 2d arrays as explained in Logic point 1. Use constants for the number of rows and columns. Step 1 Let’s begin with the creation of a ‘MineSweeper’ class and add the following main function to it.

Minesweeper.java: This class is responsible for creating the field, placing the mines and calculating the "neighbor-mines". Your minesweeper game will be a two dimensional array of buttons. I created the famous Minesweeper-game in Java, for which I used java-swing to create the GUI.Ĭontrol.java: This class contains the main-method, which just opens the GUI.
