Enjoy the classic Snake arcade game in your terminal

If you were born before the rise of smartphones like me, you might vaguely recall the small yet sturdy Nokia flip phones during your childhood or early years, loaded with simple - almost primitive - yet addictive games such as Snake and Space Invaders.

Early this year, in order to exercise the Node.js skills I acquired through taking the LFW211 course offered by the Linux Foundation, I implemented a variant of the Snake arcade game that directly runs in the terminal. It's very simple and only depends on a Node.js runtime of version no less than 10 so you can even play it on a headless server, yet it can keep you occupied with the following features:

  • 3 game maps: Unconfined (with wrapping behavior), Walled, Labyrinth
  • 4 difficulty levels per game map (the difference is speed): Easy, Medium, Hard, Insane
  • High scores for each game map + difficulty level combination that persist between game runs

Previously, the game was only packaged for Linux which comprise but a tiny fraction of the desktop / laptop user base, while the larger macOS user base could only obtain it from source or through development tools such as npm and Docker. But no more! I have recently decided to package the game for Homebrew which should be more familiar to end users, and also make it easier for users of mainstream Linux distributions to obtain the game as well by publishing packages to Ubuntu PPA and Fedora COPR, as opposed to offering the packages directly on GitHub. So let's get started!

If installing on macOS (or Linux) using Homebrew, simply enter the following two commands which add the tap DonaldKellett/games and install the formula csnaketerm from the tap:

$ brew tap DonaldKellett/games
$ brew install csnaketerm

You can then invoke the game as csnaketerm. A corresponding man page is also available:

$ man 6 csnaketerm

For Linux users, the game is available in the Snap store. This is the only packaged version that does not come with a man page, but you get a desktop launcher with icon in a GUI environment. Snaps are native to Ubuntu but come preinstalled in a number of other distributions, and can be manually installed in many more.

While Snaps are cool and all, I understand the various concerns surrounding them: bloat, vendor lock-in, lack of software freedom and such. So for those reluctant (or unable) to install Snaps, I've got you covered. On Ubuntu 20.04 LTS and later (including non-LTS releases), you can install csnaketerm from ppa:donaldsebleung/games:

$ sudo add-apt-repository ppa:donaldsebleung/games
$ sudo apt update && sudo apt install csnaketerm

On the other hand, on RPM distributions such as Fedora, CentOS and openSUSE, you can obtain csnaketerm from Fedora COPR through the donaldsebleung/games repository:

$ sudo dnf copr enable donaldsebleung/games
$ sudo dnf update && sudo dnf install csnaketerm

openSUSE users may need to first install dnf / yum and dnf-plugins-core / yum-plugin-copr accordingly.

If none of the options above (including Homebrew) worked for you as a Linux user or you are using another Unix OS such as one of the *BSD's, fetching from source is also an option. Ensure Git and Node.js 10 or above is installed, then run:

$ git clone https://github.com/DonaldKellett/csnaketerm.git

The executable and man page are both located at the top-level directory of the repo as csnaketerm and csnaketerm.6 respectively.

As for Windows users, the game unfortunately does not play well with cmd, PowerShell or even Cygwin, so it should be run in a Linux environment such as WSL2. If in doubt, get Ubuntu 20.04 LTS from the Microsoft store and follow the installation instructions for Ubuntu.

Last but not least, the source code for the game is licensed under the GNU GPL and hosted on GitHub so feel free to study the source code, fork it, and hack on the fork to your heart's desire. Happy coding, and don't forget to hit that Star button if you enjoyed the game 🌟

26