Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/magnetrwn/some-ncurses-snakes

A collection of implementations of Snake in different programming languages, using ncurses.
https://github.com/magnetrwn/some-ncurses-snakes

ncurses ncurses-game ncurses-library ncurses-tui ncurses-ui

Last synced: about 1 month ago
JSON representation

A collection of implementations of Snake in different programming languages, using ncurses.

Awesome Lists containing this project

README

        

# Some `ncurses` Snakes!

**Developing a simple version of Snake in various programming languages!**

Each folder contains a version of the game Snake for terminal that interfaces with `ncurses` to provide the game UI, or some other library in case it's not available.

I thought of this idea to learn Go, but now I want to expand it a little, just to give it a touch of many different languages.

**Make sure to check the implementation-specific READMEs, not just this one!**

## Current Implementations

+ C
+ C++
+ That's it for now :smile:

## C and C++ Version

The possible Snake algorithms I had thought of for the game were:

+ Store a list of snake node coordinates, direction, and next_direction
+ **Store a list of snake rotations and only the head coordinates, then draw backward and rotate when meeting rotation points**
+ Use a delayed tail approach, which moves the same as the head but after N steps and clears nodes instead of applying them

Since C can be considered lower level than other popular languages, I wanted to make something a bit more interesting algorithmically, so I decided to implement the snake by using a linked list of rotations (the second one). This allows the program to use memory way more efficiently to store the Snake!

Inside the `c/` or `cpp/` folder. You can find a few sources, headers and build script for Snake. Just execute the script and run `snake` once complete!

Here is an Asciinema Demo of the C version (C++ is very similar):