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 702b9812 authored by Arnaud Chevalier's avatar Arnaud Chevalier

unique id generation for player and table

parent 66378aa3
import json
from uuid import uuid4
from card import Card
from hand import Hand
class Player:
idPlayers = int(0)
# INIT
def __init__(self, name):
self.__uniqueId = Player.idPlayers
Player.idPlayers += 1
self.__uniqueId = uuid4()
self.__hand = Hand()
self.__chips = int(0)
self.__cards = []
......
from uuid import uuid4
import uuid as uuid
from flask import Flask, render_template, request, redirect, url_for, make_response, jsonify, send_from_directory
from table import Table
from player.player import Player
......@@ -100,10 +101,10 @@ def viewGame():
@app.route("/api/newGame", methods=["POST"])
def generateId():
gameId = uuid4()
nbPlayers = int(request.form['nbPlayers'])
games[str(gameId)] = Table(nbPlayers)
return str(gameId)
table = Table(nbPlayers)
games[str(table.uniqueId)] = table
return str(table.uniqueId)
@app.route('/front/<path:path>')
......
......@@ -10,7 +10,7 @@
# Then repeat the last 2 at will
#
# TODO: fix bug with wrong player action at the start of the second hand.
from uuid import uuid4
from card import Card
from hand import Hand
......@@ -31,6 +31,7 @@ class GameState(Enum):
class Table(object):
def __init__(self, maxPlayers):
self.uniqueId = uuid4()
self.maxPlayers = maxPlayers
self.gameState = GameState.IDLE
self.players = []
......
......@@ -44,8 +44,9 @@ function newgame() {
xhttp.onreadystatechange = function () {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var gameId = xhttp.responseText;
console.log(gameId)
document.getElementById("copyButton").removeAttribute("disabled")
document.getElementById("gameId").textContent = gameId;
document.getElementById("gameId").value = gameId;
}
}
var nbPlayers = document.getElementById("nbPlayers");
......
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