X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=new%2Fplomrogue%2Fgame.py;h=da8fe1a49962928d10fec5424baab8669db8a2ba;hb=0f7c3e5559d61d352ae529239e667e9da5e284fd;hp=25cb3e74fa72b5693c167af0fcee31a14eab2fcf;hpb=073618f45f297b21e90390be06cafcd430cd4d62;p=plomrogue2-experiments diff --git a/new/plomrogue/game.py b/new/plomrogue/game.py index 25cb3e7..da8fe1a 100755 --- a/new/plomrogue/game.py +++ b/new/plomrogue/game.py @@ -33,6 +33,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): @@ -84,8 +91,15 @@ class World(WorldBase): 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)) + 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 + break + t.position = new_pos self.things += [t] return t