home
·
contact
·
privacy
projects
/
plomrogue2-experiments
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
956b246
)
Minor refactoring.
author
Christian Heller
<c.heller@plomlompom.de>
Thu, 23 Nov 2017 04:38:02 +0000
(
05:38
+0100)
committer
Christian Heller
<c.heller@plomlompom.de>
Thu, 23 Nov 2017 04:38:02 +0000
(
05:38
+0100)
server.py
patch
|
blob
|
history
diff --git
a/server.py
b/server.py
index 0ef44d8e21f62edb8555227694175caf5ddb65f5..d51487d2f4a2ee303489f54b1cda7ffe5130d4bc 100755
(executable)
--- a/
server.py
+++ b/
server.py
@@
-196,6
+196,15
@@
class CommandHandler:
quoted += ['"']
return ''.join(quoted)
quoted += ['"']
return ''.join(quoted)
+ def send_all_gamestate(self):
+ """Send out game state data relevant to clients."""
+ self.send_all('NEW_TURN ' + str(self.world.turn))
+ self.send_all('MAP_SIZE ' + self.stringify_yx(self.world.map_size))
+ self.send_all('TERRAIN\n' + self.quoted(self.world.map_))
+ for thing in self.world.things:
+ self.send_all('THING TYPE:' + thing.type + ' '
+ + self.stringify_yx(thing.position))
+
def proceed_to_next_player_turn(self, connection_id):
"""Run game world turns until player can decide their next step.
def proceed_to_next_player_turn(self, connection_id):
"""Run game world turns until player can decide their next step.
@@
-218,12
+227,7
@@
class CommandHandler:
self.world.player.proceed(is_AI=False)
if self.world.player.task is None:
break
self.world.player.proceed(is_AI=False)
if self.world.player.task is None:
break
- self.send_all('NEW_TURN ' + str(self.world.turn))
- self.send_all('MAP_SIZE ' + self.stringify_yx(self.world.map_size))
- self.send_all('TERRAIN\n' + self.quoted(self.world.map_))
- for thing in self.world.things:
- self.send_all('THING TYPE:' + thing.type + ' '
- + self.stringify_yx(thing.position))
+ self.send_all_gamestate()
def cmd_FIB(self, numbers, connection_id):
"""Reply with n-th Fibonacci numbers, n taken from tokens[1:].
def cmd_FIB(self, numbers, connection_id):
"""Reply with n-th Fibonacci numbers, n taken from tokens[1:].
@@
-257,12
+261,7
@@
class CommandHandler:
self.send_all('TURN_FINISHED ' + str(self.world.turn))
sleep(1)
self.world.turn += 1
self.send_all('TURN_FINISHED ' + str(self.world.turn))
sleep(1)
self.world.turn += 1
- self.send_all('NEW_TURN ' + str(self.world.turn))
- self.send_all('MAP_SIZE ' + self.stringify_yx(self.world.map_size))
- self.send_all('TERRAIN\n' + self.quoted(self.world.map_))
- for thing in self.world.things:
- self.send_all('THING TYPE:' + thing.type + ' '
- + self.stringify_yx(thing.position))
+ self.send_all_gamestate()
self.pool_result = self.pool.map_async(fib, (35, 35))
def cmd_GET_TURN(self, connection_id):
self.pool_result = self.pool.map_async(fib, (35, 35))
def cmd_GET_TURN(self, connection_id):