Beispiel #1
0
def make_random_figure(biom):
    p = (0, 0)
    construction = {}
    for _ in range(biom[0]):
        construction[p] = Square(random.choice(biom[1]))
        p = random.choice(list(DIRS.values())).go(p)
    return construction
Beispiel #2
0
    def mech(self):
        # TODO polish things here (find-lose system)

        if self.state == 'observe':
            found = self.find_player()
            if not found:
                self.awareness = 1
                self.do_random_move()
        elif self.state == 'attack' and not self.lose_player():
            self.call_for_help(self.player)
            direction = self.find_direction_on_player()
            if self.ap >= self.points_to_attack and direction:
                self.last_happend = '\n' + self.show() + self.knife.use(direction)
            else:
                positions = [d.go(self.player.position) for d in DIRS.values()]
                if positions:
                    self.do_move_to(positions)
                    self.last_happend = ''
                    # self.last_happend = '' #'\n' + self.show() + self.do_move_to(self.player.position)
                else:
                    self.do_random_move()
                    self.last_happend = ''
        elif self.state == 'attack':
            self.state = "observe"
            self.awareness = 2
            # self.last_happend = "\n" + self.show() + " потерял игрока из виду"
        else:
            self.do_random_move()
Beispiel #3
0
 def __init__(self):
     super().__init__()
     self.kind = "странник"
     self.look = "*M"
     self.max_ap = 2
     self.direction_preference = [d for d in DIRS.values()]
     random.shuffle(self.direction_preference)
Beispiel #4
0
def make_random_blub_(material, blub_square):
    p = (0, 0)
    construction = []
    for i in range(blub_square):
        construction.append((material, p))
        p = random.choice(list(DIRS.values())).go(p)
    return construction
Beispiel #5
0
 def find_direction_on_player(self):
     for direction in DIRS.values():
         p = self.position
         for _ in self.bow.range:
             p = direction.go(p)
             if self.world.has_player_at(p):
                 return direction
             elif self.world.if_square_is(p, not_flyable):
                 break
Beispiel #6
0
def update_possible(square, possible, explored, entity):
    possible.remove(square)
    for direction in DIRS.values():
        if (entity.world.can_move(entity, direction.go(square.position))
                and direction.go(square.position) not in explored
                and distance(entity.position, direction.go(
                    square.position)) <= entity.see):
            s = Node(direction.go(square.position),
                     entity.world.board.squares[square.position].points_to_go)
            if square.value + s.cost < s.value:
                s.value = square.value + s.cost
                s.previous = square
            possible.append(s)
    return possible
Beispiel #7
0
 def mech(self):
     # TODO polish things here (find-lose system)
     if self.state == 'observe':
         found = self.find_player()
         if not found:
             self.awareness = 1
             self.do_random_move()
     elif self.state == 'attack' and not self.lose_player():
         self.call_for_help(self.player)
         direction_on_target = self.find_direction_on_player()
         if self.ap >= self.bow.cost and direction_on_target:
             self.last_happend = '\n' + self.show() + self.bow.use(
                 direction_on_target)
         elif direction_on_target:
             self.do_move_to(
                 [anti_dir(direction_on_target).go(self.position)])
             self.last_happend = '\n' + self.show(
             ) + " отходит от игрока для выстрела"
         else:
             possible_position = []
             for direction in DIRS.values():
                 p = self.player.position
                 for _ in self.bow.range:
                     p = direction.go(p)
                     if self.world.if_square_is(p, walkable_for_monsters):
                         possible_position.append(p)
                     else:
                         break
             if len(possible_position) > 0:
                 self.last_happend = ''
                 self.do_move_to(possible_position)
             else:
                 self.last_happend = ''
                 self.do_move_to([self.player.position])
     elif self.state == "observe":
         self.state = "observe"
         self.awareness = 2
         self.last_happend = "\n" + self.show() + " потерял игрока из виду"
     else:
         self.ap = 0
Beispiel #8
0
 def use(self, direction):
     self.user.ap -= self.cost
     p = direction.go(self.user.position)
     dirs = {d for d in DIRS.values() if d != anti_dir(direction)}
     queue = [p]
     visited = set()
     log_message = ""
     # FIXME Something still wrong, one mob hit twice
     while len(queue) > 0:
         a = queue.pop(0)
         if a in visited:
             continue
         visited.add(a)
         if self.user.world.if_mob_is(a, self.user.opponents):
             log_message += "\n" + self.user.hit(self.user.world.mobs[a],
                                                 self)
         queue.extend([
             d.go(a) for d in dirs
             if distance(d.go(a), self.user.position) <= self.range_
             and d.go(a) not in visited
         ])
     if len(log_message) == 0:
         return " никуда не попал хлыстом"
     return " своим хлыстом:" + log_message
Beispiel #9
0
 def find_direction_on_player(self):
     for direction in DIRS.values():
         if self.world.has_player_at(direction.go(self.position)):
             return direction
Beispiel #10
0
 def do_random_move(self):
     possibles = [d.go(self.position) for d in DIRS.values() if self.world.can_move(self, d.go(self.position))]
     if len(possibles) != 0:
         return self.do_move(random.choice(possibles))
     else:
         return " не может двигаться"