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
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):
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: