aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorulrich <ulrich.lejoyeux@gmail.com>2019-05-11 16:44:24 +0200
committerulrich <ulrich.lejoyeux@gmail.com>2019-05-11 16:44:24 +0200
commitc709dc64e02c9ffecfe55c9dff68e5d4c0eb45dd (patch)
treeb94e4d2189e2a7b57c662518531b2b5a1a1ab852
parent3afaacae022a0cdb8ad9ee6e9a599ce5ae19cbdf (diff)
pygame
-rw-r--r--.vscode/settings.json3
-rw-r--r--client/client.py92
-rw-r--r--client/snake-sprite.pngbin0 -> 57914 bytes
3 files changed, 95 insertions, 0 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..d2a6c12
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "python.pythonPath": "/usr/bin/python"
+} \ No newline at end of file
diff --git a/client/client.py b/client/client.py
new file mode 100644
index 0000000..814dac5
--- /dev/null
+++ b/client/client.py
@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+import socket, json
+import pygame
+
+RESP_BUFFER_LENGTH = 1024
+ip_adress="127.0.0.1"
+port=8080
+
+LARGEUR_BLOCK = 10
+NB_BLOCKS = 30
+LARGEUR_ECRAN = LARGEUR_BLOCK * NB_BLOCKS
+
+def connect(ip_adress, port):
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.connect((ip_adress,port))
+ return s
+
+def sendData(data):
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.connect((ip_adress,port))
+ s.sendall(data)
+ s.send('#EOF\n')
+ received = s.recv(RESP_BUFFER_LENGTH)
+ s.close()
+ return received
+
+def newGame():
+ received = sendData('{"type": "new-game"}')
+ return json.loads(received)
+
+def update(gameId = 1, direction = None):
+ data = {
+ "type" : "update",
+ "game-id": gameId,
+ "direction": direction
+ }
+ received = sendData(json.dumps(data))
+ return json.loads(received)
+
+def draw(up):
+ snake = []
+ for coords in up['SNAKE']:
+ if coords not in snake:
+ snake.append(coords)
+
+ for i in range(10):
+ s = ''
+ for j in range(10):
+ for coords in snake:
+ if coords[0] == i and coords[1] == j:
+ s = s + '*'
+ else:
+ s = s + ' '
+
+
+import pygame
+
+pygame.init()
+screen = pygame.display.set_mode((400, 300))
+done = False
+
+def main():
+ #s = connect('192.168.1.14', 8090)
+ gameInit = newGame()
+ up = update(gameInit['ID'])
+
+ """
+ while True:
+ direction = raw_input()
+ up = update(gameInit['ID'], direction)
+ draw(up)"""
+
+ continuer = True
+ pygame.init()
+ ecran = pygame.display.set_mode((LARGEUR_ECRAN,LARGEUR_ECRAN))
+
+
+ while continuer:
+ snakeSprite = pygame.image.load("snake-sprite.png")
+ snakeSprite = snakeSprite.convert_alpha()
+ pygame.draw.rect(ecran, (0,0,90), (0,0,LARGEUR_ECRAN,LARGEUR_ECRAN))
+ ecran.blit(snakeSprite, (-50,0))
+ for event in pygame.event.get():
+ if event.type == pygame.KEYDOWN:
+ continuer = False
+ pygame.display.flip()
+
+ pygame.quit()
+
+
+if __name__ == '__main__':
+ main() \ No newline at end of file
diff --git a/client/snake-sprite.png b/client/snake-sprite.png
new file mode 100644
index 0000000..d7cc983
--- /dev/null
+++ b/client/snake-sprite.png
Binary files differ