ANSI (American National Standards Institute) escape sequences allow control of the terminal just by printing specific strings. Unfortunately not all terminals support all features, so things like colors may appear differently on different terminals. I made this for Linux based systems with Docker and a Windows 10 host OS (using command prompt and Cmder).
Credit to sd9 for sections pertaining to changing the behavior of the standard input stream.
(navitage to an appropriate location first)
git clone https://github.com/calvincramer/snake_console.git snake
cd snake
If you have linux environment, skip to last step to compile and run. Also easy to do on WSL. The next steps use are for a docker environment.
docker pull ubuntu
docker build -t snake_image .
Without gdb:
docker create --name=snake -it -v <path_to_snake_folder>:/snake snake_image /bin/bash
With gdb support:
docker create --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --name=snake -it -v <path_to_snake_folder>:/snake snake_image /bin/bash
Note that your mounted folder will be different. I did mine with a Windows host machine which is probably different than Linux. Also note you can mount multiple volumes just by adding more -v
arguments.
For example, my -v <path_to_snake_folder>:/snake
looked like this:
-v //c/Users/CalvinLaptop/CalvinLaptop_Files/snake:/snake
docker start snake && docker attach snake
cd /snake
make
./snake
or
make D=1
gdb snake
use gdb to your heart's content
- note: compile with debug if you get a out of bounds compilation error.