Minesweeper is one interesting game. There is a metric buttload of clones available for the Linux distribution of your choice, but none of them really seem to fit my needs (
xbomb comes close, but wants all mines flagged).
I had programmed an engine back in 2015, but wasn't able to find a nice graphics library. After fooling around with
ncurses, which has terrible lag on mouse control (by design), I decided to use XTerm escape sequences.
The code is now available on GitHub.
hjkland similar keybindings
The current version of minesVIiper running in GNOME Terminal, with the 'color' (
-c) color scheme.
And here is (a slightly older version of) the
-d mode - running on my 1987 DEC VT220. A higher resolution version is here - you can even see the scan lines there!
This is just an excerpt; there are always new functions added. See
-h or even the source for an authoritative source.
|enable flagging (default)|
|enable question marks|
|switch to the colored scheme|
|switch to the DEC charset scheme|
|Fieldspec; width × height × mines|
The first version to run in a terminal emulator used the
ncurses library. You could notice a serious delay between pressing the mouse and seeing the cell opening. I first attributed this to sloppy coding (there were some suboptimal routines called rather often), but it turns out, even if you don't enable double and triple click handling,
ncurses still waits for you to press the mouse button again, until a timeout is reached.
By simply reimplementing the few escape/control sequences I needed, I could get rid of the delay entirely. Mouse click events are handled by a state machine, and should correctly dismiss anything non-mouse related thrown at it.
All characters that will be printed to the screen are defined in
schemes.h. By appending a new structure, you can define your own theme pretty quickly. Since very few terminal emulators can render double width characters, I default to Unicode Fullwidth characters, which renders ASCII characters at twice their width to be interspersed with Chinese, Japanese or Korean glyphs without looking out of place.
It is now 2018 and I have improved the code a bit. MinesVIiper is now using the alternate screen, space's function can now be changed at any time during the game with the a key, instead of having to pass three arguments for the field size and mine count, they are now one Fieldspec, the cursor is now shown as the sprite inverted and a few bugs have been fixed.
In version 3.14159 I finally implemented moving to "word boundaries", so b and w work as one would expect from a vi-inspired minesweeper clone. The first implementation used four nearly identical
case blocks, which I wasn't happy about. I then had the "great" idea to move that to a preprocessor macro, which cleaned the
switch right up, but I'm so looking forward to maintaining that
monstermacro. The current mode of the spacebar is now visible next to the timer.
Version 3.141592 brought revamped character schemes; mostly a new cursor highlight and a consistent flag. In 3.1415926 I implemented the same flag for the VT220 scheme as a custom character using a DECDCL down-line loadable character (set) (once again, XTerm's emulation can't handle those).
This hideous versioning scheme was finally abandoned in version 0.4. Version 0.5 introduced ex mode and from/till/after.