Commit b2b69cd2 authored by mamat-rahmat's avatar mamat-rahmat
Browse files

tambah punya linda

parent 63140f6c
......@@ -266,6 +266,11 @@ def handler(a, c):
kriteriaObject = {"token" : token}
user = database.playerCollection.find_one(kriteriaObject)
username = user['username']
#inisialisasi player_time
current_time = datetime.datetime.now()
current_time_ep = (current_time-datetime.datetime(1970,1,1)).total_seconds()
database.playerCollection.update(kriteriaObject, {"$set":{"player_time":current_time_ep}})
#write json file
data={
......@@ -289,7 +294,6 @@ def handler(a, c):
json.dump(data, f,
indent=4, separators=(',', ': '))
response = '{"status" : "ok", "name" : "' + username + '", "width" : 5, "height" : 5}'
elif (method == "move"):
#from client
token = dataJSON['token']
......@@ -303,21 +307,24 @@ def handler(a, c):
height = 5
posisiX = user['posisiX']
posisiY = user['posisiY']
time = user['player_time']
#comparing datetime
if (current_time > time):
current_time = datetime.datetime.now()
current_time_ep = (current_time-datetime.datetime(1970,1,1)).total_seconds()
if (current_time_ep > time):
#comparing position
if ((posisiX >=0) and (posisiY >= 0) and (posisiXnew < 5) and (posisiYnew < 5)):
#datetime
current_time = datetime.datetime.now()
move_time = 1
delta_second = (move_time * (abs(posisiXnew-posisiX) + abs(posisiYnew-posisiY)))
delta_milisecond = delta_second * 1000
time = current_time + datetime.timedelta(seconds=delta_second)
time = current_time_ep + datetime.timedelta(seconds=delta_second)
#update database for player_time
database.playerCollection.update(kriteriaObject, {"$set":{"player_time":time}})
response = '{"status" : "ok", "time" : delta_milisecond}'
response = '{"status" : "ok", "time" : '+ time +'}'
else:
response = '{"status" : "fail", "time" : "FAILURE MESSAGE HERE"}'
......@@ -329,6 +336,8 @@ def handler(a, c):
#Datetime
current_time = datetime.datetime.now()
current_time_ep = (current_time-datetime.datetime(1970,1,1)).total_seconds()
kriteriaObject = {'token' : token}
user = database.playerCollection.find_one(kriteriaObject)
time = user['player_time']
......@@ -346,7 +355,7 @@ def handler(a, c):
#update database inventory
kriteriaObject = {"token":token}
if (current_time >= time):
if (current_time_ep >= time):
new_n_item = n_item+1;
database.inventoriCollection.update(kriteriaObject, {"$set":{name_item_here:new_n_item}})
response = '{"status" : "ok", "item" : item_here}'
......
Supports Markdown
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