- self.player_id = 0
- self.player_is_alive = True
- self.maps = {}
-
- @property
- def player(self):
- return self.get_thing(self.player_id)
-
- def new_thing_id(self):
- if len(self.things) == 0:
- return 0
- return self.things[-1].id_ + 1
-
- def new_map(self, map_pos, size):
- self.maps[map_pos] = self.game.map_type(size)
-
- def proceed_to_next_player_turn(self):
- """Run game world turns until player can decide their next step.
-
- Iterates through all non-player things, on each step
- furthering them in their tasks (and letting them decide new
- ones if they finish). The iteration order is: first all things
- that come after the player in the world things list, then
- (after incrementing the world turn) all that come before the
- player; then the player's .proceed() is run, and if it does
- not finish his task, the loop starts at the beginning. Once
- the player's task is finished, or the player is dead, the loop
- breaks.
-
- """
- while True:
- player_i = self.things.index(self.player)
- for thing in self.things[player_i+1:]:
- thing.proceed()
- self.turn += 1
- for pos in self.maps[(0,0)]:
- if self.maps[(0,0)][pos] == '.' and \
- len(self.things_at_pos(((0,0), pos))) == 0 and \
- random.random() > 0.999:
- self.add_thing_at('food', ((0,0), pos))
- for thing in self.things[:player_i]:
- thing.proceed()
- self.player.proceed(is_AI=False)
- if self.player.task is None or not self.player_is_alive:
- break
-
- def add_thing_at(self, type_, pos):
- t = self.game.thing_types[type_](self)
- t.position = pos
- self.things += [t]
- return t
-
- def make_new(self, yx, seed):
-
- def add_thing_at_random(type_):
- while True:
- new_pos = ((0,0),
- (random.randint(0, yx[0] -1),
- random.randint(0, yx[1] -1)))
- if self.maps[new_pos[0]][new_pos[1]] != '.':
- continue
- if len(self.things_at_pos(new_pos)) > 0:
- continue
- return self.add_thing_at(type_, new_pos)
-
- self.things = []
- random.seed(seed)
- self.turn = 0
- self.maps = {}
- self.new_map((0,0), yx)
- self.new_map((0,1), yx)
- self.new_map((1,1), yx)
- self.new_map((1,0), yx)
- self.new_map((1,-1), yx)
- self.new_map((0,-1), yx)
- self.new_map((-1,-1), yx)
- self.new_map((-1,0), yx)
- self.new_map((-1,1), yx)
- for map_pos in self.maps:
- map_ = self.maps[map_pos]
- if (0,0) == map_pos:
- for pos in map_:
- map_[pos] = random.choice(('.', '.', '.', '.', 'x'))
- else:
- for pos in map_:
- map_[pos] = '~'
- player = add_thing_at_random('human')
- self.player_id = player.id_
- add_thing_at_random('monster')
- add_thing_at_random('monster')
- add_thing_at_random('food')
- add_thing_at_random('food')
- add_thing_at_random('food')
- add_thing_at_random('food')
- return 'success'
-
-
-
-class Game:
-
- def __init__(self, game_file_name):