Backend for a snake game where the screen is an ESP8266 controlled strip of Neopixels and the controller is a web page.
See also the client and the screen-controlling microprocessor.
GET /state
Checks whether there is an active game.
Returns a JSON document with the field
status
set to playing
if there is a game.
All other values can be interpreted as no game is running.
GET /screen
Returns the current board as a string of characters where each character represents a pixel.
The values can be parsed as:
0
pixel off1
part of snake2
a fruit
If the request returns status HTTP/404
it means the game is over.
POST /play
Starts a new game.
The response returns a JSON document
which contains a playerToken
.
This token must be included in all subsequent
requests when controlling the game.
If a game is already running
this request will return HTTP/400
.
POST /action
Sends a command to move the snake. The body of the request must be form-data with these fields:
playerToken
: The token returned when a new game was startedkeyPressed
: A character representing the button that was pressed. See below for possible values.
Key presses
U
: move upD
: Move downL
: Move leftR
: Move rightX
: (Re)start game
All other values will return an error.