Merge pull request 'added points in stats;' (#41) from stats_update into master

Reviewed-on: #41
This commit is contained in:
Angelika Iskra 2022-06-09 23:57:18 +02:00
commit f4aa9741e3
4 changed files with 29 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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