Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 557dfbba authored by Arnaud Chevalier's avatar Arnaud Chevalier

client ask its cards

parent 06070c12
import json
from card import Card
from hand import Hand
......@@ -6,7 +8,7 @@ class Player:
idPlayers = int(0)
# INIT
def __init__(self):
def __init__(self, name):
self.__uniqueId = Player.idPlayers
Player.idPlayers += 1
self.__hand = Hand()
......@@ -17,7 +19,7 @@ class Player:
self.__hasHadAction = bool(False)
self.__isPlaying = bool(False)
self.__isAllIn = bool(False)
self.__name = ""
self.__name = name
# GETTERS & SETTERS
def isPlaying(self):
......@@ -148,3 +150,8 @@ class Player:
# Timeout, shouldn't be needed (just check/fold called from Table)
def yieldAction(self):
self.__hasHadAction = True
def state(self):
return json.dumps({
"cards": [card.cardStr() for card in self.__cards]
})
......@@ -24,7 +24,7 @@ def gameState():
return response
@app.route("/game/action", methods=["POST"]) # TODO: add GET posssible actions
@app.route("/game/action", methods=["POST"])
def action():
act = request.form
if act["name"] == "bet":
......@@ -36,3 +36,22 @@ def action():
elif act["name"] == "check":
game.check(game.activePlayer)
return
@app.route("/game/newPlayer", method=["POST"])
def newPlayer():
req = request.form
p = Player(req["name"])
game.addPlayer(p)
return p.uniqueId
@app.route("/game/player")
def getPlayer():
player = filter(lambda x: x.uniqueId == request.headers["playerId"], game.players)
response = app.response_class(
response=player.state(),
status=200,
mimetype='application/json'
)
return response
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment