GitHub - ebarlas/minesweeper-csp: Minesweeper implemented in Java using virtual...
source link: https://github.com/ebarlas/minesweeper-csp
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
ebarlas/minesweeper-csp
Minesweeper CSP
Minesweeper CSP is a Java implementation of Microsoft Minesweeper using communicating sequential processes (CSP).
Each game tile is an independent, anonymous process and all communication occurs via (buffered) channels. No explicit synchronization primitives are used beyond channels.
It's built atop virtual threads, defined in JDK Enhancement Proposal (JEP) 425 and available as a preview feature starting in Java 19.
The virtual threads feature is part of Project Loom.
Prior to virtual threads, CSP-style programming in this manner simply wasn't available in Java.
Build
An OpenJDK 19 or later build is required. At the time of this writing, virtual
threads are a preview feature. That is why --enable-preview
is provided below.
Build with mvn
:
mvn compile
java --enable-preview -cp target/classes/ minesweeper.Main
Compile with javac
:
javac --enable-preview -source 19 src/main/java/minesweeper/*.java -d build/
java --enable-preview -cp build/ minesweeper.Main
Command Line Arguments
Include beginner
, intermediate
, or advanced
command-line argument to select a difficulty.
java --enable-preview -cp build/ minesweeper.Main advanced
Difficulty | Rows | Columns | Mines | Mine Density |
---|---|---|---|---|
Beginner | 9 | 9 | 10 | 12% |
Intermediate | 16 | 16 | 40 | 16% |
Advanced | 16 | 30 | 99 | 21% |
Assets
All game assets were created from scratch in Inkscape and rasterized to PNG images.
Processes
Every tile runs in its own process, defined in Cell.java. Cell processes communicate with each other via channels.
The game controller runs in its own process, defined in Game.java.
The window runs in its own process, defined in Window.java.
Finally, the clock runs in its own process, defined in Clock.java.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK