X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=new%2Fplomrogue%2Fgame.py;h=103d705b90287ed51a1ab32ddeadacfc743b638a;hb=b8feda3f8948c579b086a9b5559849cd585f9929;hp=25cb3e74fa72b5693c167af0fcee31a14eab2fcf;hpb=073618f45f297b21e90390be06cafcd430cd4d62;p=plomrogue2-experiments diff --git a/new/plomrogue/game.py b/new/plomrogue/game.py index 25cb3e7..103d705 100755 --- a/new/plomrogue/game.py +++ b/new/plomrogue/game.py @@ -13,6 +13,7 @@ from plomrogue.parser import Parser from plomrogue.io import GameIO from plomrogue.misc import quote, stringify_yx from plomrogue.things import Thing, ThingMonster, ThingHuman, ThingFood +import random @@ -33,6 +34,13 @@ class WorldBase: return t return None + def things_at_pos(self, yx): + things = [] + for t in self.things: + if t.position == yx: + things += [t] + return things + class World(WorldBase): @@ -73,21 +81,34 @@ class World(WorldBase): for thing in self.things[player_i+1:]: thing.proceed() self.turn += 1 + for pos in self.map_: + if self.map_[pos] == '.' and \ + len(self.things_at_pos(pos)) == 0 and \ + random.random() > 0.999: + self.add_thing_at('food', 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): - import random - def add_thing(type_): - t = self.game.thing_types[type_](self) - t.position = (random.randint(0, yx[0] -1), - random.randint(0, yx[1] - 1)) - self.things += [t] - return t + def add_thing_at_random(type_): + while True: + new_pos = (random.randint(0, yx[0] -1), + random.randint(0, yx[1] - 1)) + if self.map_[new_pos] != '.': + continue + if len(self.things_at_pos(new_pos)) > 0: + continue + return self.add_thing_at(type_, new_pos) self.things = [] random.seed(seed) @@ -99,14 +120,14 @@ class World(WorldBase): continue self.map_[pos] = random.choice(('.', '.', '.', '.', 'x')) - player = add_thing('human') + player = add_thing_at_random('human') self.player_id = player.id_ - add_thing('monster') - add_thing('monster') - add_thing('food') - add_thing('food') - add_thing('food') - add_thing('food') + 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'