A tiny snake game using curses.
Do you need a manual?
This is still work in progress. So far, it features a scoring system, clock and randomly placed obstacles. Of course it handles any terminal size, as long as it's not smaller than 80x25. Resizing the terminal while running is not handled ... it's a silly idea trying to resize a board game in action. Just don't do it :). Windows users: If you want bigger boards, create a link to the executable. In the link properties, you can configure the window size (among other things).
Colors are obviously a matter of being lucky with curses .. this screenshot above looks ok, so how do you like this version of good old xterm?
Thanks to PDcurses (and a tiny bit of platform specific tweaking), it even works fine on windows:
... as well as on DOS (this looks crazy on a 1920x1200 display):
... here we can have this old MS DOS smiley as the snake head -- great! :)
working on a highscore list. That's the only thing still missing from my idea of a first release.
Just type make
. You will end up with a binary in the bin
subdir.
(If not, you're missing development files for curses
-- on Linux, this is
normally ncurses
-- or they are in a nonstandard location. Set your CFLAGS
and LDFLAGS
environment variable so that curses
headers and libs are
found.)
some more options to make
:
USELTO=0
(defaults to1
): Enable or disable link time optimizationsGCC32=1
(defaults to0
): On x86_64, build an x86 binaryDEBUG=1
(defaults to0
): Build with debugging info (-g3
), disable optimizations (-O0
)
Try LDFLAGS=-fuse-ld=gold make CC=clang
.
You need a DJGPP
toolchain. Install it,
then compile the PDcurses
lib with it. pdcurses.a
goes in the lib
directory of your toolchain (e.g. /usr/local/i586-pc-msdosdjgpp/lib
), named
libpdcurses.a
. Place the header curses.h
in the include
directory of
your toolchain (e.g. /usr/local/i586-pc-msdosdjgpp/include
). Then, the
following command will do:
make CROSS_COMPILE=i586-pc-msdosdjgpp- PLATFORM=dos strip
To make it run correctly under plain DOS, you need a DPMI server (Windows 9x
already provides one). DJGPP links the .exe with a stub that tries to run
CWSDPMI.EXE if no DPMI services are detected. This will not work because
cursed snake uses the privileged HLT
instruction to save power when running
under plain DOS and CWSDPMI puts the code in ring 3
. First, you have to
download the CWSDPMI binary distribution
from here. Then there are two
possibilities to have cursed snake run in ring 0
, so it can use HLT
:
-
Modify the stub linked by DJGPP to load CWSDPR0.EXE instead:
/[...]/i586-pc-msdosdjgpp/bin/stubedit bin/csnake.exe dpmi=CWSDPR0.EXE
With this, the CWSDPR0.EXE must be in the same directory as csnake.exe to run it.
-
Replace the stub with CWSDSTR0.EXE:
/[...]/i586-pc-msdosdjgpp/bin/exe2coff bin/csnake.exe
cat /path/to/CWSDSTR0.EXE bin/csnake >bin/csnake.exe
The resulting binary will run on its own even in plain DOS, because it has the CWS DPMI server embedded.
So you don't have a GNU toolchain on your machine but would like to try this out just for fun? Here are some builds (redone from time to time):
- Windows 32bit (.exe)
- Linux 32bit (ELF binary)
- Linux 64bit (ELF binary)
- MS-DOS / Win 9x (.exe)