From 3591fedfa276837251fae7f462d25179ef24454b Mon Sep 17 00:00:00 2001 From: Angelika Iskra Date: Thu, 9 Jun 2022 23:56:26 +0200 Subject: [PATCH] added points in stats; --- common/constants.py | 2 +- logic/game.py | 1 + logic/level.py | 17 +++++++++++++++++ ui/stats.py | 12 ++++++++++-- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/common/constants.py b/common/constants.py index 16cb000..86f2d15 100644 --- a/common/constants.py +++ b/common/constants.py @@ -6,7 +6,7 @@ GAME_TITLE = 'WMICraft' WINDOW_HEIGHT = 800 WINDOW_WIDTH = 1360 FPS_COUNT = 60 -TURN_INTERVAL = 100 +TURN_INTERVAL = 200 GRID_CELL_PADDING = 5 GRID_CELL_SIZE = 36 diff --git a/logic/game.py b/logic/game.py index 5bf6e60..c1c2464 100644 --- a/logic/game.py +++ b/logic/game.py @@ -45,6 +45,7 @@ class Game: # create level level.create_map() stats = Stats(self.screen, level.list_knights_blue, level.list_knights_red) + level.setup_stats(stats) print_numbers_flag = False running = True diff --git a/logic/level.py b/logic/level.py index 9ea5ebd..a59e889 100644 --- a/logic/level.py +++ b/logic/level.py @@ -31,6 +31,15 @@ class Level: 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): self.map = import_random_map() self.setup_base_tiles() @@ -116,11 +125,13 @@ class Level: some_knight.health_bar.take_dmg(current_knight.attack) if some_knight.health_bar.current_hp <= 0: some_knight.kill() + self.add_points(current_knight.team, 5) for monster in self.list_monsters: if monster.position == position_left: monster.health_bar.take_dmg(current_knight.attack) if monster.health_bar.current_hp <= 0: monster.kill() + self.add_points(current_knight.team, monster.points) else: current_knight.health_bar.take_dmg(monster.attack) if current_knight.health_bar.current_hp <= 0: @@ -137,11 +148,13 @@ class Level: some_knight.health_bar.take_dmg(current_knight.attack) if some_knight.health_bar.current_hp == 0: some_knight.kill() + self.add_points(current_knight.team, 5) for monster in self.list_monsters: if monster.position == position_right: monster.health_bar.take_dmg(current_knight.attack) if monster.health_bar.current_hp <= 0: monster.kill() + self.add_points(current_knight.team, monster.points) else: current_knight.health_bar.take_dmg(monster.attack) if current_knight.health_bar.current_hp <= 0: @@ -157,11 +170,13 @@ class Level: some_knight.health_bar.take_dmg(current_knight.attack) if some_knight.health_bar.current_hp == 0: some_knight.kill() + self.add_points(current_knight.team, 5) for monster in self.list_monsters: if monster.position == position_up: monster.health_bar.take_dmg(current_knight.attack) if monster.health_bar.current_hp <= 0: monster.kill() + self.add_points(current_knight.team, monster.points) else: current_knight.health_bar.take_dmg(monster.attack) if current_knight.health_bar.current_hp <= 0: @@ -177,11 +192,13 @@ class Level: some_knight.health_bar.take_dmg(current_knight.attack) if some_knight.health_bar.current_hp == 0: some_knight.kill() + self.add_points(current_knight.team, 5) for monster in self.list_monsters: if monster.position == position_down: monster.health_bar.take_dmg(current_knight.attack) if monster.health_bar.current_hp <= 0: monster.kill() + self.add_points(current_knight.team, monster.points) else: current_knight.health_bar.take_dmg(monster.attack) if current_knight.health_bar.current_hp <= 0: diff --git a/ui/stats.py b/ui/stats.py index 7cb97ab..2bd75df 100644 --- a/ui/stats.py +++ b/ui/stats.py @@ -23,6 +23,8 @@ class Stats: pygame.Rect(self.x + 210, self.y + 210, 100, 15), 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])) + self.blue_team_points = 0 + self.red_team_points = 0 def update(self): @@ -55,5 +57,11 @@ class Stats: # points 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: 10', FONT_DARK, self.screen, self.x + 215, 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: ' + 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 -- 2.20.1