This commit is contained in:
ksjdragon 2016-01-20 20:39:36 -05:00
commit 8f1b6d97f4

View File

@ -13,10 +13,10 @@ maxPlayers = 2
initialTime = 0 initialTime = 0
timeLeft = 3 timeLeft = 3
def RandomMove(playerStatus): def RandomMove(username):
x = [1,0] x = [1,0]
random.shuffle(x) 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 # Renders client
@ -30,17 +30,21 @@ def update_game():
# What to do when the Client tells the server something # What to do when the Client tells the server something
if request.method == 'POST': if request.method == 'POST':
if "timeLeft" in game:
del game["timeLeft"]
noMove = game.keys()
global timeLeft global timeLeft
# Define the data given by client # Define the data given by client
playerStatus = request.get_json(force=True) playerStatus = request.get_json(force=True)
if timeLeft == 3: if timeLeft == 3:
origin = time.time() timeLeft = time.time()
if len(playerStatus[playerStatus.keys()[0]]) == 1: if len(playerStatus[playerStatus.keys()[0]]) == 1:
if playerStatus[playerStatus.keys()[0]][0] == "death": if playerStatus[playerStatus.keys()[0]][0] == "death":
del game[playerStatus["username"]] del game[playerStatus.keys()[0]]
del noMove[noMove.index(playerStatus.keys()[0])]
else: else:
global color global color
global vertical global vertical
@ -61,22 +65,29 @@ def update_game():
# If the username that the player sent is already defined in game # If the username that the player sent is already defined in game
elif playerStatus["username"] in game: elif playerStatus["username"] in game:
if abs(playerStatus["coordinate"][0]) + abs(playerStatus["coordinate"][1]) == 1: elif abs(playerStatus["coordinate"][0]) + abs(playerStatus["coordinate"][1]) == 1:
if playerStatus["username"] in noMove:
coord1 = playerStatus["coordinate"][0] + game[playerStatus["username"]][0][0] coord1 = playerStatus["coordinate"][0] + game[playerStatus["username"]][0][0]
coord2 = playerStatus["coordinate"][1] + game[playerStatus["username"]][0][1] coord2 = playerStatus["coordinate"][1] + game[playerStatus["username"]][0][1]
game[playerStatus["username"]][0] = [coord1, coord2] game[playerStatus["username"]][0] = [coord1, coord2]
del noMove[noMove.index(playerStatus["username"])]
else: else:
print "Hax?" print "Hax?"
RandomMove(playerStatus) RandomMove(playerStatus["username"])
del noMove[noMove.index(playerStatus["username"])]
else: else:
return "Hax" return "Hax"
# Return the game with the information you added, in addition to everyone else # 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) time.sleep(0.1)
for player in noMove:
RandomMove(player)
timeLeft = 3 timeLeft = 3
return jsonify(game) return jsonify(game)