task(*self.task.args, **self.task.kwargs)
self.task = None
if is_AI and self.task is None:
task(*self.task.args, **self.task.kwargs)
self.task = None
if is_AI and self.task is None:
'xxxxx'
self.things = [Thing('human', [3, 3]), Thing('monster', [1, 1])]
self.player_i = 0
'xxxxx'
self.things = [Thing('human', [3, 3]), Thing('monster', [1, 1])]
self.player_i = 0
"""Transform tuple (y,x) into string 'Y:'+str(y)+',X:'+str(x)."""
return 'Y:' + str(tuple_[0]) + ',X:' + str(tuple_[1])
"""Transform tuple (y,x) into string 'Y:'+str(y)+',X:'+str(x)."""
return 'Y:' + str(tuple_[0]) + ',X:' + str(tuple_[1])
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.
thing.proceed()
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))
thing.proceed()
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))
for thing in self.world.things:
self.send_all('THING TYPE:' + thing.type + ' '
+ self.stringify_yx(thing.position))
for thing in self.world.things:
self.send_all('THING TYPE:' + thing.type + ' '
+ self.stringify_yx(thing.position))
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.world.turn += 1
self.send_all('NEW_TURN ' + str(self.world.turn))
self.send_all('MAP_SIZE ' + self.stringify_yx(self.world.map_size))
for thing in self.world.things:
self.send_all('THING TYPE:' + thing.type + ' '
+ self.stringify_yx(thing.position))
for thing in self.world.things:
self.send_all('THING TYPE:' + thing.type + ' '
+ self.stringify_yx(thing.position))
def cmd_move(self, direction, connection_id):
"""Set player task to 'move' with direction arg, finish player turn."""
def cmd_move(self, direction, connection_id):
"""Set player task to 'move' with direction arg, finish player turn."""
- if not direction in {'UP', 'DOWN', 'RIGHT', 'LEFT'}:
+ if direction not in {'UP', 'DOWN', 'RIGHT', 'LEFT'}:
raise ArgumentError('MOVE ARGUMENT MUST BE ONE OF: '
'UP, DOWN, RIGHT, LEFT')
self.world.player.set_task('move', direction=direction)
raise ArgumentError('MOVE ARGUMENT MUST BE ONE OF: '
'UP, DOWN, RIGHT, LEFT')
self.world.player.set_task('move', direction=direction)