TQ
dev.com

Blog about software development

Subscribe

Minesweeper written in Go using Fyne

05 Apr 2024 - by 'Maurits van der Schee'

It was already 3 years ago that I wrote Minesweeper for Ebiten in Go. I wanted to try to bring the application to desktop. I have ported that implementation from using the Ebiten game engine to desktop using the Fyne GUI library and I have just released version 1.0.0 that can be run on Windows and Linux.

Download

You can download the Windows and Linux releases from Github:

https://github.com/mevdschee/fyne-mines

It is a portable (single-file) executable without any dependencies.

Graphics and rules

"Minesweeper X" by Curtis Bright is IMHO the best implementation of Minesweeper ever made. He also provided a skinning system. For the rules of the game I have been reading the MinesweeperGame.com website. As a reference I have also looked at the great Minesweeper Online implementation in Javascript.

Go with Fyne or with Ebitengine?

I have found that Fyne is really good for creating simple cross-platform apps, while Ebitengine is really good for creating simple cross-platform games. The main difference is that Ebiten redraws the entire screen on every tick (immediate mode), while Fyne knows about widgets that are arranged in a certain layout and refreshed on demand (retained mode).

So many controls

You get nice controls like label, button, entry, form, progressbar, mainmenu. This allows you to make some great cross-platform GUI applications that look the same on every platform. Important is that the systray (menu) is supported (with a native control) so that you can write a small tool that auto-starts and stays there.

Cross compiling

Cross-platform is support is even more magical due to the cross-compiling support. You can build easily build your Windows executable on Linux. I tried to run the resulting Windows executable under Wine and succeeded.

Performance

On desktop the Fyne engine runs pretty fast and as long as I didn't redraw the entire field on every interaction the graphics were nice and fast (as expected). I also tried to run the Fyne version via WASM, but it was much slower and also very large (28 megabytes WASM file). I have read that using Firefox makes the WASM files run slower (compared to Chromium), but also the Ebiten implementation run via WASM was much faster.

Conclusion

If you are building a small desktop tool, then Fyne may be the optimal choice. Consistent GUI across platforms, fast and easy to compile, cross-compile, package and publish. If you are building a (small) game, then you'd better stick to Ebiten. For any more serious web application I would use Typescript as I did for AceCardGames.com.

NB: If you liked this article, you may also like my next article on creating a 2D puzzle game in Go using Fyne.

Links


PS: Liked this article? Please share it on Facebook, Twitter or LinkedIn.