finished server-side of turn-based

This commit is contained in:
yamanq 2016-01-19 23:26:25 -05:00
parent c1672e6087
commit 1b8fd24c14

View File

@ -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)