2.5 KiB
2.5 KiB
Remote Snake API
General Description
-
All transmissions will be based on TCP since:
- Packet length are not fixed (large variance depending on the snake size and food)
- Packet ordering is important (inverted request can compromise gameplay)
-
All TCP streams from client to server will:
- Contain plain json data
- Be terminated by an "#EOF" line (in order for the server to detect the end of the client request)
- All TCP stream from server to client will contains plain json data (connection will be closed by the server so, there is no need of "#EOF").
Communications
Initialisation
-
Client sent:
{ "type": "new-game" } #EOF
-
Server can reply:
{ "type": "state", "game-id": 1, "game-over": false, "snake": [[1,2],[1,3]], "food": [[6,7]] }
Gameplay
Change Direction
-
When client is playing a game, it can ask the server to change snake direction:
{ "type": "update", "game-id": 1, "direction": "left", } #EOF
-
Then, server can reply:
{ "type": "state", "game-id": 1, "game-over": false, "snake": [[0,2],[1,2]], "food": [[6,7]] }