A Minesweeper game implemented using JavaFX. This project demonstrates a classic Minesweeper game with a graphical user interface, complete with cell-reveal, flagging, flood-fill for empty cells, and win/lose detection.
PATH
or module path is set up to reference the JavaFX SDK libraries.This project is contained in a single Java file:
MinesweeperFX.java
Open a terminal in the directory where MinesweeperFX.java
is located.
Compile the application using the following command (adjust the path to your JavaFX SDK’s lib
folder):
javac --module-path /path/to/javafx-sdk/lib --add-modules javafx.controls MinesweeperFX.java
Replace /path/to/javafx-sdk/lib
with the actual path to your JavaFX SDK library directory.
After compiling, run the application with:
java --module-path /path/to/javafx-sdk/lib --add-modules javafx.controls MinesweeperFX
Again, replace /path/to/javafx-sdk/lib
with the correct path for your environment.
Game Initialization:
The board is initialized with a 16x16 grid of cells. Mines are randomly placed, and adjacent mine counts are computed for each cell.
private static final int ROWS = 16;
private static final int COLS = 16;
private static final int MINES = 40;
Contributions are welcome! Feel free to fork this repository, make improvements, and submit pull requests. Whether it’s adding new features or improving the UI, your input is valuable.
This project is licensed under the MIT License.
Enjoy playing Minesweeper with JavaFX and happy coding!