home · contact · privacy
Fix faulty assumption about position of player in world.things.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 12 Dec 2018 00:40:17 +0000 (01:40 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 12 Dec 2018 00:40:17 +0000 (01:40 +0100)
game_common.py
server.py
server_/game.py

index 6a77d9c6fa0c5062f73a1b089089416bc054c82e..c6fb220ee04cfa7ba90ee512e4239e24fd45b69e 100644 (file)
@@ -27,11 +27,11 @@ class World:
         self.terrain_map = self.terrain_map[:y * width_map] + line + \
                            self.terrain_map[(y + 1) * width_map:]
 
-    def get_thing(self, i):
+    def get_thing(self, id_):
         for thing in self.things:
-            if i == thing.id_:
+            if id_ == thing.id_:
                 return thing
-        t = self.Thing(self, i)
+        t = self.Thing(self, id_)
         self.things += [t]
         return t
 
index 3e1ae6f1881f8ed9afc0f7a819c550da2b3da224..912a6927148129ad99250bf870ebcc1620017ed2 100755 (executable)
--- a/server.py
+++ b/server.py
@@ -170,21 +170,18 @@ class CommandHandler:
         self.world.proceed_to_next_player_turn()
         self.send_all_gamestate()
 
-    def get_player(self):
-        return self.world.get_thing(self.world.player_id)
-
     def cmd_MOVE(self, direction, connection_id):
         """Set player task to 'move' with direction arg, finish player turn."""
         if direction not in {'UP', 'DOWN', 'RIGHT', 'LEFT'}:
             raise ArgError('Move argument must be one of: '
                            'UP, DOWN, RIGHT, LEFT')
-        self.get_player().set_task('move', direction=direction)
+        self.world.get_player().set_task('move', direction=direction)
         self.proceed()
     cmd_MOVE.argtypes = 'string'
 
     def cmd_WAIT(self, connection_id):
         """Set player task to 'wait', finish player turn."""
-        self.get_player().set_task('wait')
+        self.world.get_player().set_task('wait')
         self.proceed()
 
     def cmd_MAP_SIZE(self, yx, connection_id):
index da2f61184b43bce0052d42139c438fd6fee7e54c..148c5c7c8fd9db3909df52eea4213ce6284476df 100644 (file)
@@ -38,16 +38,20 @@ class World(game_common.World):
         the player's task is finished, the loop breaks.
         """
         while True:
-            for thing in self.things[self.player_id+1:]:
+            player = self.get_player()
+            player_i = self.things.index(player)
+            for thing in self.things[player_i+1:]:
                 thing.proceed()
             self.turn += 1
-            for thing in self.things[:self.player_id]:
+            for thing in self.things[:player_i]:
                 thing.proceed()
-            player = self.get_thing(self.player_id)
             player.proceed(is_AI=False)
             if player.task is None:
                 break
 
+    def get_player(self):
+        return self.get_thing(self.player_id)
+
 
 class Task: