Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
lancarjodoh
IF3230-Tugas-Besar-Sister-2015
Commits
6c97bdc4
Commit
6c97bdc4
authored
Apr 26, 2015
by
Linda Sekawati
Browse files
Move belum selese
parent
7bfbe308
Changes
1
Hide whitespace changes
Inline
Side-by-side
bin/server/mainserver_nonthread.py
View file @
6c97bdc4
...
...
@@ -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'}"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment