Merge pull request 'actually WORKING!!!!! one-direction attack with no ghost-knights (only knights, no monsters and fortress)' (#38) from knights_attack_v2 into master
Reviewed-on: #38
This commit is contained in:
commit
cb9b8e6b2d
@ -6,7 +6,7 @@ GAME_TITLE = 'WMICraft'
|
|||||||
WINDOW_HEIGHT = 800
|
WINDOW_HEIGHT = 800
|
||||||
WINDOW_WIDTH = 1360
|
WINDOW_WIDTH = 1360
|
||||||
FPS_COUNT = 60
|
FPS_COUNT = 60
|
||||||
TURN_INTERVAL = 500
|
TURN_INTERVAL = 100
|
||||||
|
|
||||||
GRID_CELL_PADDING = 5
|
GRID_CELL_PADDING = 5
|
||||||
GRID_CELL_SIZE = 36
|
GRID_CELL_SIZE = 36
|
||||||
|
@ -10,7 +10,7 @@ class KnightsQueue:
|
|||||||
def dequeue_knight(self):
|
def dequeue_knight(self):
|
||||||
if self.both_teams_alive():
|
if self.both_teams_alive():
|
||||||
knight = self.queues[self.team_idx_turn].popleft()
|
knight = self.queues[self.team_idx_turn].popleft()
|
||||||
if knight.max_hp <= 0:
|
if knight.health_bar.current_hp <= 0:
|
||||||
return self.dequeue_knight()
|
return self.dequeue_knight()
|
||||||
else:
|
else:
|
||||||
self.queues[self.team_idx_turn].append(knight)
|
self.queues[self.team_idx_turn].append(knight)
|
||||||
|
@ -92,13 +92,7 @@ class Level:
|
|||||||
self.map[row_index][col_index] = castle
|
self.map[row_index][col_index] = castle
|
||||||
self.list_castles.append(castle)
|
self.list_castles.append(castle)
|
||||||
|
|
||||||
def handle_turn(self):
|
def attack_knight(self, knights_list, positions, current_knight):
|
||||||
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]
|
op_pos_1 = current_knight.position[0] - 1, current_knight.position[1]
|
||||||
positions.append(op_pos_1)
|
positions.append(op_pos_1)
|
||||||
op_pos_2 = current_knight.position[0], current_knight.position[1] - 1
|
op_pos_2 = current_knight.position[0], current_knight.position[1] - 1
|
||||||
@ -107,6 +101,53 @@ class Level:
|
|||||||
positions.append(op_pos_3)
|
positions.append(op_pos_3)
|
||||||
op_pos_4 = current_knight.position[0], current_knight.position[1] + 1
|
op_pos_4 = current_knight.position[0], current_knight.position[1] + 1
|
||||||
positions.append(op_pos_4)
|
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,
|
goal_list = self.decision_tree.predict_move(grid=self.map, current_knight=current_knight,
|
||||||
monsters=self.list_monsters,
|
monsters=self.list_monsters,
|
||||||
@ -114,6 +155,9 @@ class Level:
|
|||||||
if current_knight.team_alias() == 'k_r' else self.list_knights_red,
|
if current_knight.team_alias() == 'k_r' else self.list_knights_red,
|
||||||
castle=self.list_castles[0])
|
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:
|
if len(goal_list) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -126,10 +170,18 @@ 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 current_knight.health_bar.current_hp != 0:
|
||||||
if some_knight.position == some_position:
|
#self.attack_knight(knights_list, positions, current_knight)
|
||||||
some_knight.health_bar.take_dmg(1)
|
|
||||||
|
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:
|
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.')
|
||||||
@ -163,3 +215,6 @@ class Level:
|
|||||||
# update and draw the game
|
# update and draw the game
|
||||||
self.sprites.draw(self.screen)
|
self.sprites.draw(self.screen)
|
||||||
self.sprites.update()
|
self.sprites.update()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class Stats:
|
|||||||
# texts
|
# texts
|
||||||
draw_text('Rycerze: ' + str(len(self.list_knights_blue)), FONT_DARK, self.screen, self.x + 35, self.y + 240, 18) # blue
|
draw_text('Rycerze: ' + str(len(self.list_knights_blue)), FONT_DARK, self.screen, self.x + 35, self.y + 240, 18) # blue
|
||||||
|
|
||||||
draw_text('Rycerze: 4', FONT_DARK, self.screen, self.x + 215, self.y + 240, 18)
|
draw_text('Rycerze: ' + str(len(self.list_knights_red)), FONT_DARK, self.screen, self.x + 215, self.y + 240, 18)
|
||||||
|
|
||||||
# points
|
# points
|
||||||
pygame.draw.rect(self.screen, ORANGE, pygame.Rect(self.x, self.y + 390, 340, 3))
|
pygame.draw.rect(self.screen, ORANGE, pygame.Rect(self.x, self.y + 390, 340, 3))
|
||||||
|
Loading…
Reference in New Issue
Block a user