added points in stats;

This commit is contained in:
Angelika Iskra 2022-06-09 23:56:26 +02:00
parent 050a0359b0
commit 3591fedfa2
4 changed files with 29 additions and 3 deletions

View File

@ -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 = 100 TURN_INTERVAL = 200
GRID_CELL_PADDING = 5 GRID_CELL_PADDING = 5
GRID_CELL_SIZE = 36 GRID_CELL_SIZE = 36

View File

@ -45,6 +45,7 @@ class Game:
# create level # create level
level.create_map() level.create_map()
stats = Stats(self.screen, level.list_knights_blue, level.list_knights_red) stats = Stats(self.screen, level.list_knights_blue, level.list_knights_red)
level.setup_stats(stats)
print_numbers_flag = False print_numbers_flag = False
running = True running = True

View File

@ -31,6 +31,15 @@ class Level:
self.knights_queue = None self.knights_queue = None
self.stats = None
def setup_stats(self, stats):
self.stats = stats
def add_points(self, team, points_to_add):
if self.stats is not None:
self.stats.add_points(team, points_to_add)
def create_map(self): def create_map(self):
self.map = import_random_map() self.map = import_random_map()
self.setup_base_tiles() self.setup_base_tiles()
@ -116,11 +125,13 @@ class Level:
some_knight.health_bar.take_dmg(current_knight.attack) some_knight.health_bar.take_dmg(current_knight.attack)
if some_knight.health_bar.current_hp <= 0: if some_knight.health_bar.current_hp <= 0:
some_knight.kill() some_knight.kill()
self.add_points(current_knight.team, 5)
for monster in self.list_monsters: for monster in self.list_monsters:
if monster.position == position_left: if monster.position == position_left:
monster.health_bar.take_dmg(current_knight.attack) monster.health_bar.take_dmg(current_knight.attack)
if monster.health_bar.current_hp <= 0: if monster.health_bar.current_hp <= 0:
monster.kill() monster.kill()
self.add_points(current_knight.team, monster.points)
else: else:
current_knight.health_bar.take_dmg(monster.attack) current_knight.health_bar.take_dmg(monster.attack)
if current_knight.health_bar.current_hp <= 0: if current_knight.health_bar.current_hp <= 0:
@ -137,11 +148,13 @@ class Level:
some_knight.health_bar.take_dmg(current_knight.attack) some_knight.health_bar.take_dmg(current_knight.attack)
if some_knight.health_bar.current_hp == 0: if some_knight.health_bar.current_hp == 0:
some_knight.kill() some_knight.kill()
self.add_points(current_knight.team, 5)
for monster in self.list_monsters: for monster in self.list_monsters:
if monster.position == position_right: if monster.position == position_right:
monster.health_bar.take_dmg(current_knight.attack) monster.health_bar.take_dmg(current_knight.attack)
if monster.health_bar.current_hp <= 0: if monster.health_bar.current_hp <= 0:
monster.kill() monster.kill()
self.add_points(current_knight.team, monster.points)
else: else:
current_knight.health_bar.take_dmg(monster.attack) current_knight.health_bar.take_dmg(monster.attack)
if current_knight.health_bar.current_hp <= 0: if current_knight.health_bar.current_hp <= 0:
@ -157,11 +170,13 @@ class Level:
some_knight.health_bar.take_dmg(current_knight.attack) some_knight.health_bar.take_dmg(current_knight.attack)
if some_knight.health_bar.current_hp == 0: if some_knight.health_bar.current_hp == 0:
some_knight.kill() some_knight.kill()
self.add_points(current_knight.team, 5)
for monster in self.list_monsters: for monster in self.list_monsters:
if monster.position == position_up: if monster.position == position_up:
monster.health_bar.take_dmg(current_knight.attack) monster.health_bar.take_dmg(current_knight.attack)
if monster.health_bar.current_hp <= 0: if monster.health_bar.current_hp <= 0:
monster.kill() monster.kill()
self.add_points(current_knight.team, monster.points)
else: else:
current_knight.health_bar.take_dmg(monster.attack) current_knight.health_bar.take_dmg(monster.attack)
if current_knight.health_bar.current_hp <= 0: if current_knight.health_bar.current_hp <= 0:
@ -177,11 +192,13 @@ class Level:
some_knight.health_bar.take_dmg(current_knight.attack) some_knight.health_bar.take_dmg(current_knight.attack)
if some_knight.health_bar.current_hp == 0: if some_knight.health_bar.current_hp == 0:
some_knight.kill() some_knight.kill()
self.add_points(current_knight.team, 5)
for monster in self.list_monsters: for monster in self.list_monsters:
if monster.position == position_down: if monster.position == position_down:
monster.health_bar.take_dmg(current_knight.attack) monster.health_bar.take_dmg(current_knight.attack)
if monster.health_bar.current_hp <= 0: if monster.health_bar.current_hp <= 0:
monster.kill() monster.kill()
self.add_points(current_knight.team, monster.points)
else: else:
current_knight.health_bar.take_dmg(monster.attack) current_knight.health_bar.take_dmg(monster.attack)
if current_knight.health_bar.current_hp <= 0: if current_knight.health_bar.current_hp <= 0:

View File

@ -23,6 +23,8 @@ class Stats:
pygame.Rect(self.x + 210, self.y + 210, 100, 15), pygame.Rect(self.x + 210, self.y + 210, 100, 15),
current_hp=sum([knight.get_current_hp() for knight in self.list_knights_red]), current_hp=sum([knight.get_current_hp() for knight in self.list_knights_red]),
max_hp=sum([knight.get_max_hp() for knight in self.list_knights_red])) max_hp=sum([knight.get_max_hp() for knight in self.list_knights_red]))
self.blue_team_points = 0
self.red_team_points = 0
def update(self): def update(self):
@ -55,5 +57,11 @@ class Stats:
# 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))
draw_text('PUNKTY: 10', FONT_DARK, self.screen, self.x + 35, self.y + 408, 18, True) draw_text('PUNKTY: ' + str(self.blue_team_points), FONT_DARK, self.screen, self.x + 35, self.y + 408, 18, True)
draw_text('PUNKTY: 10', FONT_DARK, self.screen, self.x + 215, self.y + 408, 18, True) draw_text('PUNKTY: ' + str(self.red_team_points), FONT_DARK, self.screen, self.x + 215, self.y + 408, 18, True)
def add_points(self, team, points):
if team == "blue":
self.blue_team_points += points
else:
self.red_team_points += points