Commit 6c97bdc4 authored by Linda Sekawati's avatar Linda Sekawati
Browse files

Move belum selese

parent 7bfbe308
......@@ -3,6 +3,7 @@ import json
import hashlib
import pymongo
import threading
import datetime
from pymongo import MongoClient
from random import randint
......@@ -403,19 +404,55 @@ def playserver(portLaptop):
else:
response = "{'status' : 'fail', 'description' : 'offer is not available'}"
elif (method == 'map'):
#random number for width and height
width = randint(5,15)
height = width
#tokem from client
token = dataJSON['token']
kriteriaObject = {"token" : token}
#for update
kriteria1Object = {"$set":{"width":width}}
kriteria2Object = {"$set":{"height":height}}
database.playerCollection.update(kriteriaObject,kriteria1Object)
database.playerCollection.update(kriteriaObject,kriteria2Object)
response = '{"status" : "ok", "name" : "Bandar Behari", "width" : ' + str(width) + ', "height" : ' + str(height) + '}'
elif (method == 'move'):
response = '{"status" : "ok", "time" : 123456}'
#from client
token = dataJSON['token']
posisiXnew = dataJSON['posisiX']
posisiYnew = dataJSON['posisiY']
#from database
user = database.playerCollection.find(token)
width = user['width']
height = user['height']
posisiX = user['posisiX']
posisiY = user['posisiY']
#datetime
current_time = datetime.datetime.now()
move_time = 1
delta_second = (move_time * (abs(posisiXnew-posisiX) + abs(posisiYnew-posisiY)))
player_time = current_time + datetime.timedelta(seconds=delta_second)
#update database for player_time
database.playerCollection.update(kriteriaObject, {"$set":{"player_time":player_time}})
#comparing datetime
if (current_time > player_time):
#comparing position
if ((posisiX >=0) and (posisiY >= 0) and (posisiXnew < width) and (posisiYnew < height)):
response = '{"status" : "ok", "time" : delta_second}'
else:
response = '{"status" : "fail", "time" : "FAILURE MESSAGE HERE"}'
elif (method == 'field'):
response = '{"status" : "ok", "item" : 2}'
#
#if ((current_time > player_time) and ):
# response = '{"status" : "ok", "item" : 2}'
#else:
response = '{"status" : "fail", "time" : "FAILURE MESSAGE HERE"}'
else:
response = "{'status' : 'error'}"
......
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