Snake Attack banner

Snake Attack

2 devlogs
21h 18m 15s

A multiplayer snake game built by me and playable from terminals.

Repository

Loading README...

Alex Lu

Oops. Sometimes with long hours of work, you’re getting carried away in the zone. Other times, it’s not so productive. These 15 hours were a bit of both (just kidding, 100% the latter), while I tried to figure out sockets and networking.
As a noob to networking protocols and asynchronous threads (especially in Python), keeping track of execution points was a big source of frustration for me. For just about 8 hours, I was rerunning the client and server programs over and over to try to understand why sockets were disconnecting preemptively. This led me to a couple findings about the code and the process of fixing code.
Before starting, mock up just 2-10 lines of rules about data typing, which thread is in charge of what, and when to clean up. This will save one from tons of confusion later on.
Secondly, debugging sucks when everything depends on the implementation of everything else. While, not exactly a direct solution, I found that just thinking without the code can reduce the overhead to solutions if you do get stuck in a hole like this.

Next, real-time games process drawing and events independently of input. I needed to figure out how to use my existing input system with threading in order to get info from the server without waiting for input. Attempting to start a thread with just a getch call will fail with no actual inputs, as it is a thread-safe, blocking call.
The obvious idea was to just use a library tracking the actual keyboard, however this was not ideal. I wanted to limit dependencies, and capturing keys wasn’t quite the solution I wanted.
I eventually, went back to the documentation and… immediately found the function I needed.

Taking on unfamiliar tasks can be difficult, result in great frustrations, and a severe lack of sleep, but these experiences are integral to growing, and it feels darn good to overcome a big hurdle. ; 1

Attachment
0
Alex Lu

Hihi. I wanted to learn about multiplayer games and tcp connections so I decided to recreate a classic game in multiplayer!

This first session was in procrastination of important homework and job hunting so ermm…

  • Set up a project
  • Figured out basic connections with Python’s socket library
  • Created some classes for creating snake body parts and stuff
  • Imported tGame modules, an old project of mine for input buffers, drawing, and more for the terminal
  • Figured out pyproject.toml w/ hatchling
  • Basic movement w/ threaded input
Attachment
0