A desire to experiment with web technologies, as well as some new languages we were not familiar with. We based the concept off games like, and decided to see how far we could get in 36 hours with no prior experience with any of the major tools used.

What it does

A broswer based multiplayer snake game, where an unlimited number of players have joint control over two snakes.

When either snake dies the game instantly resets and keeps running.

How I built it

The web server is written in c++ using the boost::beast library to manage websockets, able to dynamically open and close near unlimited simultaneous connections without problem. The main game engine is also written in c++, with a main game loop running in it's own thread for as long as the server is active.

The server is running in docker on a google cloud ubuntu virtual machine. This is at ip

The client is a javascript/html page which opens a new websocket to the server on page load, and takes inputs from wasd and the arrow keys to control the snake when connected.

We set up a website,, to forward to the ip of the server, but the dns registration process apparently takes several hours longer than we expected, so it might not be online yet.

Challenges I ran into

For me (adam) this was the first time working with any of the tools.

I had zero prior experience with c++, (very very limited experience with c on small handins prior.) No prior experience with docker. No prior experience with server setup/management/ssh. No prior experience with javascript or websockets.

This meant that things went wrong a lot. It took about 12 hours for us to get our web server working at all, as the boost::beast library is very complex for language beginners and designed for massively scalable servers, and serves as the backend for huge games like and Special thanks to the wizards who helped a lot with various issues.

The c++ code was also completely new to me, and i spent many hours on strange bugs, such as 90 minutes saturday evening trying to work out why std::string str = x + "," + y (with x and y as ints) was printing variable sections of the c++ source library to my server.

Accomplishments that I'm proud of

There were several points which were very satisfying. Getting the initial snake game working, after a day of experimentation, was a high point.

Then getting the main game thread loop running, after a several hours of experimentation and wizard help, with an anonymous lambda declaration allowing us to call our non static game loop into a new thread.

Finally the progress made in the last 6 hours, once the game loop and server were set up, and I was starting to get comfortable with c++ syntax, where death, food spawns, the second snake, basic movement interpolation and a whole host of other features were very quickly and easily added.

What I learned

How to write c++ How to set up a robust c++ server capable of large scaling and automatic websocket allocation and destruction How to set up a cloud server and ssh into it. How docker works, and how to set up docker images on a ubuntu server How to debug docker images How to write an html/javascript webpage How to initiate and use websocket connections between the webpage and the server

What's next for Snek

The goals which I didn't have time for were mainly giving each client control over their own snake, and maybe making game size variable based off number of players.

As the server should support up to hundreds of players, with a bit of refactoring of game.cpp to spin the snake object off into it's own class, then store a list of snakes to iterate over, this should be very easily scalable.

Built With

Share this project: