fixed knights_hp + basic attack ^<>v (improvement in progress)

This commit is contained in:
AleksandraMuczynska 2022-06-08 12:51:09 +02:00
parent 9afd1f366a
commit e31364b21c
2 changed files with 16 additions and 1 deletions

View File

@ -94,9 +94,19 @@ class Level:
def handle_turn(self): def handle_turn(self):
current_knight = self.knights_queue.dequeue_knight() current_knight = self.knights_queue.dequeue_knight()
knights_list = self.list_knights_red + self.list_knights_blue
print("next turn " + current_knight.team) print("next turn " + current_knight.team)
knight_pos_x = current_knight.position[0] knight_pos_x = current_knight.position[0]
knight_pos_y = current_knight.position[1] 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, goal_list = self.decision_tree.predict_move(grid=self.map, current_knight=current_knight,
monsters=self.list_monsters, monsters=self.list_monsters,
@ -116,6 +126,11 @@ class Level:
return return
next_action = action_list.pop(0) 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: if next_action == TURN_LEFT:
self.logs.enqueue_log(f'AI {current_knight.team}: Obrót w lewo.') self.logs.enqueue_log(f'AI {current_knight.team}: Obrót w lewo.')
current_knight.rotate_left() current_knight.rotate_left()

View File

@ -37,7 +37,7 @@ class Knight(pygame.sprite.Sprite):
self.attack = random.randint(4, 7) self.attack = random.randint(4, 7)
self.defense = random.randint(1, 4) self.defense = random.randint(1, 4)
self.points = 1 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): def rotate_left(self):
self.direction = self.direction.left() self.direction = self.direction.left()