Commit 7429e0a5 authored by Linda Sekawati's avatar Linda Sekawati
Browse files

Random Map to Database

parent ccaddb50
......@@ -137,7 +137,7 @@ def playserver(portLaptop):
tokenuser = objectToken.hexdigest();
# insert player baru di playerCollection, insert inventori kosong
kriteria1Object = {"token" : tokenuser, "username" : username, "password" : password, "posisiX" : 0, "posisiY" : 0, "player_time" : 0}
kriteria1Object = {"token" : tokenuser, "username" : username, "password" : password, "posisiX" : 0, "posisiY" : 0, "player_time" : 0, "width" : 0, "height" : 0}
kriteria2Object = {"token" : tokenuser, "honey" : 3, "herbs" : 3, "clay" : 3, "mineral" : 0, "potion" : 0, "incense" : 0, "gems" : 0, "elixir" : 0, "crystal" : 0, "stone" : 0}
database.playerCollection.insert(kriteria1Object)
database.inventoriCollection.insert(kriteria2Object)
......@@ -170,11 +170,13 @@ def playserver(portLaptop):
print(user)
posisiX = user['posisiX']
posisiY = user['posisiY']
width = user['width']
height = user['height']
time = user['player_time']
tokenuser = user['token']
print(tokenuser)
# tulis response
response = "{'status' : 'ok','token' : '" + tokenuser + "','x' : " + str(posisiX) + " ,'y' : " + str(posisiY) + ",'time' : " + str(time) + "}"
response = "{'status' : 'ok','token' : '" + tokenuser + "','x' : " + str(posisiX) + " ,'y' : " + str(posisiY) + ",'time' : " + str(time) + ",'width' : " + str(width) + ",'height' : " + str(height) + "}"
else: # user belum terdaftar, keluarkan status gagal
response = "{'status' : 'fail', 'description' : 'username/password combination is not found'}"
elif (method == 'inventory'):
......@@ -403,6 +405,12 @@ def playserver(portLaptop):
elif (method == 'map'):
width = randint(5,15)
height = width
token = dataJSON['token']
kriteriaObject = {"token" : token}
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}'
......
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