Commit 5a0484e14eafb855e0013ddcbd05bd96d1307a26

Authored by Mestari Yousra
1 parent beb9f486

code frappe serveur

Showing 1 changed file with 56 additions and 0 deletions   Show diff stats
frappe_serveur.py 0 → 100644
... ... @@ -0,0 +1,56 @@
  1 +import time
  2 +import zmq
  3 +import numpy as np
  4 +import builtins
  5 +
  6 +context = zmq.Context()
  7 +socket = context.socket(zmq.ROUTER)
  8 +socket.bind("tcp://*:5555")
  9 +
  10 +
  11 +def frappe(J,M,position):
  12 + socket.send_multipart([J.addr,b'',b"Quelle case frapper?"])
  13 + J.addr,empty,case=socket.recv_multipart()
  14 + case=case.decode()
  15 + print(case)
  16 + k=f(case[0])-1
  17 + l=int(case[1])-1
  18 + while M2[k][l]==1:
  19 + M2[k][l]=2
  20 + position[(k,l)]=position[(k,l)][0],2
  21 + elem=position[(k,l)][0]
  22 + print(M2)
  23 + #verifier si le bateau est coule
  24 + i=0
  25 + for cle in position.keys():
  26 + if position[cle][0]==elem and position[cle][1]==2:
  27 + i+=1
  28 + if i==elem.longueur:
  29 + coule=elem.nom+" coule!"
  30 + socket.send_multipart([J.addr,b'',coule.encode()])
  31 + for cle in position.keys():
  32 + if position[cle][0]==elem:
  33 + M2[cle[0]][cle[1]]=3
  34 + position[cle]=position[cle][0],3
  35 + #verifier si le jeu est gagne
  36 + j=0
  37 + for cle in position.keys():
  38 + if position[cle][1]==3:
  39 + j+=1
  40 + if j==18:
  41 + victoire= J1.nom+" a gagne!"
  42 + socket.send_multipart([J.addr,b"",victoire])
  43 + message="jeu fini"
  44 + victoire=J.nom + "a gagne!"
  45 + quit
  46 + #sinon, continuer
  47 + else:
  48 + socket.send_multipart([J.addr,b'',b"Touche!"])
  49 + socket.send_multipart([J.addr,b'',b"Quelle case frapper?"])
  50 + J.addr,empty,frappe=socket.recv_multipart()
  51 + frappe=frappe.decode()
  52 + print(frappe)
  53 + k=f(frappe[0])-1
  54 + l=int(frappe[1])-1
  55 + socket.send_multipart([J.addr,b'',b"Manque! C'est le tour de l'autre joueur maintenant."])
  56 + return(message, victoire ,M,position)
0 57 \ No newline at end of file
... ...