|
|
|
@ -92,13 +92,7 @@ class Level:
|
|
|
|
|
self.map[row_index][col_index] = castle
|
|
|
|
|
self.list_castles.append(castle)
|
|
|
|
|
|
|
|
|
|
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 = []
|
|
|
|
|
def attack_knight(self, knights_list, positions, current_knight):
|
|
|
|
|
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
|
|
|
|
@ -107,6 +101,53 @@ class Level:
|
|
|
|
|
positions.append(op_pos_3)
|
|
|
|
|
op_pos_4 = current_knight.position[0], current_knight.position[1] + 1
|
|
|
|
|
positions.append(op_pos_4)
|
|
|
|
|
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 some_knight.health_bar.current_hp == 0:
|
|
|
|
|
some_knight.kill()
|
|
|
|
|
positions.clear()
|
|
|
|
|
|
|
|
|
|
def attack_knight_left(self, knights_list, current_knight):
|
|
|
|
|
position_left = current_knight.position[0] - 1, current_knight.position[1]
|
|
|
|
|
for some_knight in knights_list:
|
|
|
|
|
if some_knight.position == position_left:
|
|
|
|
|
some_knight.health_bar.take_dmg(1)
|
|
|
|
|
if some_knight.health_bar.current_hp == 0:
|
|
|
|
|
some_knight.kill()
|
|
|
|
|
|
|
|
|
|
def attack_knight_right(self, knights_list, current_knight):
|
|
|
|
|
position_right = current_knight.position[0] + 1, current_knight.position[1]
|
|
|
|
|
for some_knight in knights_list:
|
|
|
|
|
if some_knight.position == position_right:
|
|
|
|
|
some_knight.health_bar.take_dmg(1)
|
|
|
|
|
if some_knight.health_bar.current_hp == 0:
|
|
|
|
|
some_knight.kill()
|
|
|
|
|
|
|
|
|
|
def attack_knight_up(self, knights_list, current_knight):
|
|
|
|
|
position_up = current_knight.position[0] , current_knight.position[1] - 1
|
|
|
|
|
for some_knight in knights_list:
|
|
|
|
|
if some_knight.position == position_up:
|
|
|
|
|
some_knight.health_bar.take_dmg(1)
|
|
|
|
|
if some_knight.health_bar.current_hp == 0:
|
|
|
|
|
some_knight.kill()
|
|
|
|
|
|
|
|
|
|
def attack_knight_down(self, knights_list, current_knight):
|
|
|
|
|
position_down = current_knight.position[0], current_knight.position[1] + 1
|
|
|
|
|
for some_knight in knights_list:
|
|
|
|
|
if some_knight.position == position_down:
|
|
|
|
|
some_knight.health_bar.take_dmg(1)
|
|
|
|
|
if some_knight.health_bar.current_hp == 0:
|
|
|
|
|
some_knight.kill()
|
|
|
|
|
|
|
|
|
|
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 = []
|
|
|
|
|
|
|
|
|
|
goal_list = self.decision_tree.predict_move(grid=self.map, current_knight=current_knight,
|
|
|
|
|
monsters=self.list_monsters,
|
|
|
|
@ -114,6 +155,9 @@ class Level:
|
|
|
|
|
if current_knight.team_alias() == 'k_r' else self.list_knights_red,
|
|
|
|
|
castle=self.list_castles[0])
|
|
|
|
|
|
|
|
|
|
if (len(self.list_knights_blue) == 0 or len(self.list_knights_red) == 0):
|
|
|
|
|
pygame.quit()
|
|
|
|
|
|
|
|
|
|
if len(goal_list) == 0:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
@ -126,10 +170,18 @@ 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 current_knight.health_bar.current_hp != 0:
|
|
|
|
|
#self.attack_knight(knights_list, positions, current_knight)
|
|
|
|
|
|
|
|
|
|
if current_knight.direction.name == UP:
|
|
|
|
|
self.attack_knight_up(knights_list, current_knight)
|
|
|
|
|
elif current_knight.direction.name == DOWN:
|
|
|
|
|
self.attack_knight_down(knights_list, current_knight)
|
|
|
|
|
elif current_knight.direction.name == RIGHT:
|
|
|
|
|
self.attack_knight_right(knights_list, current_knight)
|
|
|
|
|
elif current_knight.direction.name == LEFT:
|
|
|
|
|
self.attack_knight_left(knights_list, current_knight)
|
|
|
|
|
|
|
|
|
|
if next_action == TURN_LEFT:
|
|
|
|
|
self.logs.enqueue_log(f'AI {current_knight.team}: Obrót w lewo.')
|
|
|
|
@ -163,3 +215,6 @@ class Level:
|
|
|
|
|
# update and draw the game
|
|
|
|
|
self.sprites.draw(self.screen)
|
|
|
|
|
self.sprites.update()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|