From 8b37db0401f0523a4c81cfb905e0914a9bdd3ca3 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 23 Nov 2017 05:38:02 +0100 Subject: [PATCH] Minor refactoring. --- server.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/server.py b/server.py index 0ef44d8..d51487d 100755 --- a/server.py +++ b/server.py @@ -196,6 +196,15 @@ class CommandHandler: 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. @@ -218,12 +227,7 @@ class CommandHandler: 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:]. @@ -257,12 +261,7 @@ class CommandHandler: 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): -- 2.30.2