def act(self, level): player = level.player dirs = util.dir_of(self.pos, player.pos) # Randomly try horizontal or vertical movement direction = random.choice(dirs) try: try: self.walk(direction) except monster.MoveBump, e: if e.monster == player: self.attack(direction, e.monster) except monster.MoveError: pass
def act(self, level): player = level.player dirs = util.dir_of(self.pos, player.pos) for direction in dirs: try: try: self.walk(direction) return except monster.MoveBump, e: if e.monster == player: self.attack(direction, e.monster) return except monster.MoveError: pass