diff --git a/client/client.py b/client/client.py index 7bded0e..9e33207 100644 --- a/client/client.py +++ b/client/client.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python2.7 # -*- coding: utf-8 -*- import socket, json, time import pygame @@ -76,22 +77,22 @@ def handleControls(event, gameId): def main(): gameInit = newGame() - gameId = gameInit['ID'] + gameId = gameInit['id'] up = gameInit - initSize=len(up['SNAKE']) + initSize=len(up['snake']) continuer = True while continuer: - afficher(ecran, up['SNAKE'], up['FOOD']) - ecran.blit(myfont.render('Score {}'.format(len(up['SNAKE'])-initSize), False, (0, 0, 0)),(0,0)) + afficher(ecran, up['snake'], up['food']) + ecran.blit(myfont.render('Score {}'.format(len(up['snake'])-initSize), False, (0, 0, 0)),(0,0)) for event in pygame.event.get(): if event.type == pygame.QUIT: continuer = False elif event.type == pygame.KEYDOWN: updateTmp = handleControls(event, gameId) print(updateTmp) - if updateTmp != None and 'TYPE' in updateTmp: - if updateTmp['TYPE'] != 'error': + if updateTmp != None and 'type' in updateTmp: + if updateTmp['type'] != 'error': up = updateTmp time.sleep(0.3) pygame.display.flip() diff --git a/doc/api.org b/doc/api.org index e5da347..736fe55 100644 --- a/doc/api.org +++ b/doc/api.org @@ -4,14 +4,10 @@ #+LATEX_HEADER: \usepackage{fullpage} * 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"). + - All transmissions will be based on UDP since latency is important + - All UDP datagrams between *client and server* will contain _plain json data_ + - All data should be sent in *one* datagram + - All utf-8 characters in UDP datagram are in lower case * Communications ** Initialisation 1. Client sent: @@ -19,7 +15,6 @@ { "type": "new-game" } - #EOF #+END_SRC 2. Server can reply: #+BEGIN_SRC json @@ -40,7 +35,6 @@ "game-id": 1, "direction": "left", } - #EOF #+END_SRC 2. Then, server can reply: #+BEGIN_SRC json @@ -60,7 +54,6 @@ "game-id": 1, "direction": null } - #EOF #+END_SRC 2. Server can reply: #+BEGIN_SRC json diff --git a/doc/api.pdf b/doc/api.pdf index 34d125b..e5615e4 100644 Binary files a/doc/api.pdf and b/doc/api.pdf differ diff --git a/server/api/api.lisp b/server/api/api.lisp index 6d91f57..a87cf6c 100644 --- a/server/api/api.lisp +++ b/server/api/api.lisp @@ -43,8 +43,9 @@ (let* ((game-id (create-game gm))) (let ((game-dump (dump gm game-id))) (setf (getf game-dump :game-over) :null) ; Define nil as null (for json) - (to-json - (append (list :type "state") game-dump)))))) + (string-downcase + (to-json + (append (list :type "state") game-dump))))))) (defmethod handle-update ((api api) data) (with-slots (gm) api @@ -54,8 +55,9 @@ (if dir (refresh game :dir dir) (refresh game)) - (to-json - (append (list :type "state") (dump gm game-id)))))) + (string-downcase + (to-json + (append (list :type "state") (dump gm game-id))))))) (defmethod handle-request ((api api) request)