blob: 67cece79e0e5e27bd421f8e041236609957f05ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# -*- 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():
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 + ' '
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)
"""
|