From 1b8fd24c1400ef44403537ae054cc9806dc05c3b Mon Sep 17 00:00:00 2001 From: yamanq Date: Tue, 19 Jan 2016 23:26:25 -0500 Subject: [PATCH 1/2] finished server-side of turn-based --- clashingcomrades/server.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/clashingcomrades/server.py b/clashingcomrades/server.py index 1c6d111..6350e1d 100644 --- a/clashingcomrades/server.py +++ b/clashingcomrades/server.py @@ -13,10 +13,10 @@ maxPlayers = 2 initialTime = 0 timeLeft = 3 -def RandomMove(playerStatus): +def RandomMove(username): x = [1,0] random.shuffle(x) - game[playerStatus["username"]][0] = [x[0] + game[playerStatus["username"]][0][0], x[1] + game[playerStatus["username"]][0][1]] + game[username][0] = [x[0] + game[username][0][0], x[1] + game[username][0][1]] # Renders client @@ -30,17 +30,21 @@ def update_game(): # What to do when the Client tells the server something if request.method == 'POST': + if "timeLeft" in game: + del game["timeLeft"] + noMove = game.keys() global timeLeft # Define the data given by client playerStatus = request.get_json(force=True) if timeLeft == 3: - origin = time.time() + timeLeft = time.time() if len(playerStatus[playerStatus.keys()[0]]) == 1: if playerStatus[playerStatus.keys()[0]][0] == "death": del game[playerStatus["username"]] + del noMove[noMove.index(playerStatus["username"])] else: global color global vertical @@ -65,18 +69,24 @@ def update_game(): coord1 = playerStatus["coordinate"][0] + game[playerStatus["username"]][0][0] coord2 = playerStatus["coordinate"][1] + game[playerStatus["username"]][0][1] game[playerStatus["username"]][0] = [coord1, coord2] + del noMove[noMove.index(playerStatus["username"])] else: print "Hax?" - RandomMove(playerStatus) + RandomMove(playerStatus["username"]) + del noMove[noMove.index(playerStatus["username"])] else: return "Hax" # Return the game with the information you added, in addition to everyone else - while (time.time() - origin) < 3: + while (time.time() - timeLeft) < 3: time.sleep(0.1) + + + for player in noMove: + RandomMove(player) timeLeft = 3 return jsonify(game) From 950ccd06846f6ce9f00a59a0ecda28116c33743b Mon Sep 17 00:00:00 2001 From: yamanq Date: Wed, 20 Jan 2016 20:31:50 -0500 Subject: [PATCH 2/2] bug fixes --- clashingcomrades/server.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/clashingcomrades/server.py b/clashingcomrades/server.py index 6350e1d..b8904bf 100644 --- a/clashingcomrades/server.py +++ b/clashingcomrades/server.py @@ -43,8 +43,8 @@ def update_game(): if len(playerStatus[playerStatus.keys()[0]]) == 1: if playerStatus[playerStatus.keys()[0]][0] == "death": - del game[playerStatus["username"]] - del noMove[noMove.index(playerStatus["username"])] + del game[playerStatus.keys()[0]] + del noMove[noMove.index(playerStatus.keys()[0])] else: global color global vertical @@ -65,11 +65,12 @@ def update_game(): # If the username that the player sent is already defined in game elif playerStatus["username"] in game: - if abs(playerStatus["coordinate"][0]) + abs(playerStatus["coordinate"][1]) == 1: - coord1 = playerStatus["coordinate"][0] + game[playerStatus["username"]][0][0] - coord2 = playerStatus["coordinate"][1] + game[playerStatus["username"]][0][1] - game[playerStatus["username"]][0] = [coord1, coord2] - del noMove[noMove.index(playerStatus["username"])] + elif abs(playerStatus["coordinate"][0]) + abs(playerStatus["coordinate"][1]) == 1: + if playerStatus["username"] in noMove: + coord1 = playerStatus["coordinate"][0] + game[playerStatus["username"]][0][0] + coord2 = playerStatus["coordinate"][1] + game[playerStatus["username"]][0][1] + game[playerStatus["username"]][0] = [coord1, coord2] + del noMove[noMove.index(playerStatus["username"])] else: print "Hax?"