diff --git a/logic/level.py b/logic/level.py index 9f43721..df2c462 100644 --- a/logic/level.py +++ b/logic/level.py @@ -94,9 +94,19 @@ class Level: def handle_turn(self): current_knight = self.knights_queue.dequeue_knight() + knights_list = self.list_knights_red + self.list_knights_blue print("next turn " + current_knight.team) knight_pos_x = current_knight.position[0] knight_pos_y = current_knight.position[1] + positions = [] + op_pos_1 = current_knight.position[0] - 1, current_knight.position[1] + positions.append(op_pos_1) + op_pos_2 = current_knight.position[0], current_knight.position[1] - 1 + positions.append(op_pos_2) + op_pos_3 = current_knight.position[0] + 1, current_knight.position[1] + positions.append(op_pos_3) + op_pos_4 = current_knight.position[0], current_knight.position[1] + 1 + positions.append(op_pos_4) goal_list = self.decision_tree.predict_move(grid=self.map, current_knight=current_knight, monsters=self.list_monsters, @@ -116,6 +126,11 @@ class Level: return next_action = action_list.pop(0) + for some_knight in knights_list: + for some_position in positions: + if some_knight.position == some_position: + some_knight.health_bar.take_dmg(1) + if next_action == TURN_LEFT: self.logs.enqueue_log(f'AI {current_knight.team}: ObrĂ³t w lewo.') current_knight.rotate_left() diff --git a/models/knight.py b/models/knight.py index 05eabfc..39c2679 100644 --- a/models/knight.py +++ b/models/knight.py @@ -37,7 +37,7 @@ class Knight(pygame.sprite.Sprite): self.attack = random.randint(4, 7) self.defense = random.randint(1, 4) self.points = 1 - self.health_bar = HealthBar(screen, self.rect, current_hp=random.randint(1, self.max_hp), max_hp=self.max_hp, calculate_xy=True, calculate_size=True) + self.health_bar = HealthBar(screen, self.rect, current_hp=self.max_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True) def rotate_left(self): self.direction = self.direction.left()