The Snake Bash Game is a classic arcade-style game that you can play directly from your terminal.
SNAKE BASH
SCORE 3 | BEST 7 | FPS 10.0
# # # # # # # # # # # # # # #
# #
# * * * #
# #
# $ #
# #
# # # # # # # # # # # # # # #
arrows/4682 move +/- speed p pause
r restart q quit
To start the game, run the following command in your terminal:
npx snake-bashIf you install it as a global dependency you can use the shortcut snake-bash.
Use the arrow keys to move the snake, optionally:
4: move left6: move right8: move up2: move down
+/-: speed the snake up or slow it downporspace: pauser: restart the gameqorCtrl+C: quit the game
snake-bash --size 20 # a 20x20 board
snake-bash --size 15x40 # 15 rows, 40 columns
snake-bash --fps 15 # start faster
snake-bash --no-color # plain output
snake-bash --helpColours are also disabled automatically when the output is not a terminal, or
when NO_COLOR is set.
The best score lasts for as long as the game is running and is deliberately never written to disk. Snake Bash reads no files, writes no files, opens no sockets and has no runtime dependencies, which is what makes it safe to drop onto a machine you care about and delete afterwards.
Terminals flicker when a game blanks the screen and repaints it from scratch on every frame. Snake Bash never blanks the screen: it keeps the previous frame in memory, works out which lines actually changed, and rewrites only those, in place, as a single write to stdout. A frame where nothing moved costs no output at all.
The game also runs on the alternate screen buffer, so quitting gives you your
prompt and scrollback back exactly as you left them, and the terminal is
restored on every exit path, including Ctrl+C and unexpected errors.
To customize this game, you can clone the repository and install the dependencies (linters and nothing else -- the game itself has zero runtime dependencies):
git clone https://github.com/gabrielmissio/snake-bash.git
cd snake-bash
npm installYou can then make changes to the code and run the game using:
npm startRun the checks with:
npm test # unit tests, via the built-in node:test runner
npm run lintSet OUTPUT_MODE=DevelopmentOutput to get plain, escape-free frames, which is
handy when piping the output somewhere or debugging the board state:
OUTPUT_MODE=DevelopmentOutput npm startsrc/
backgrounds/ the walls the board is built from
components/ board, snake and target
inputs/ raw keyboard reading and key decoding
outputs/ frame composition, diffing renderer, terminal modes
main/ game manager, loop, CLI entry point
utils/ enums and small helpers
Requires Node.js 18 or newer.
This project is licensed under the MIT License. See the LICENSE file for details.