ClojureScript minesweeper game with p5.js

#clojurescript#p5js

Here’s a simple (and incomplete) minesweeper game implemented with ClojureScript, p5.js and shadow-cljs. The code is in my demo collection on GitHub.

gameplay

Click on a cell to reval it. If it’s a bomb, you lose. You win by revealing all cells that are not bombs. To start a new game just click anywhere on the grid. (There’s no flag-support)

Unfortunately, it seems I got the flood-reveal code wrong because it doesn’t reveal the outermost diagonal cells.

The game lacks several features that are common to minesweeper games, like the ability to add flags and chose difficulty level. I actually found another ClojureScript + p5.js minesweeper at https://sneakycode.net/minesweeper that has all those things, I recommend you take a look.

Two technical things that are bugging me: how to handle game state and configuration settings in a way that’s clean and scalable.

p5.js uses global callbacks, and I felt I had to use global variables (atoms) so that the callbacks could find them. Maybe a cleaner solution is to use a single global state variable that the non-callback functions could deconstruct.

I “stored” the configuration settings in a function called config that returns a map with all the settings. It’s a mess. If I were to use a single global state variable it might make sense to store the settings in there.