feat: add score, lines and level calc
This commit is contained in:
@@ -38,13 +38,12 @@ class Game:
|
||||
self.main_music = mixer.Channel(0)
|
||||
self.well = Well((280, 80), ConfigurationManager.get("color", "well-1"), ConfigurationManager.get("color", "well-border-1")) # TODO calculate position later and redo color config for well
|
||||
self.stack = Stack(ConfigurationManager.get("color", "stack-1"), ConfigurationManager.get("color", "stack-border-1"))
|
||||
self.score = 0
|
||||
|
||||
loaded_icon = pygame.image.load(win_icon)
|
||||
pygame.display.set_caption(win_title)
|
||||
pygame.display.set_icon(loaded_icon)
|
||||
|
||||
self.is_pressing_down = False # TODO move into control util later
|
||||
|
||||
main_music_file = ConfigurationManager.get("sound", "main-music")
|
||||
self.main_music.set_volume(0.7) # TODO add volume to the config
|
||||
self.main_music.play(mixer.Sound(main_music_file), -1)
|
||||
@@ -63,14 +62,13 @@ class Game:
|
||||
sys.exit()
|
||||
|
||||
if self.stack:
|
||||
self.stack.update(elapsed_time)
|
||||
self.stack.update(elapsed_time, self)
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
|
||||
def draw(self) -> None:
|
||||
# TODO write not initialized exception
|
||||
|
||||
@@ -85,18 +83,24 @@ class Game:
|
||||
self.stack.draw(self.screen)
|
||||
if self.current_piece:
|
||||
self.current_piece.draw(self.screen, self.well, self.stack)
|
||||
|
||||
#TextGenerator.draw("12345678901234567890123456789012345678901234567890", (0, 0), self.screen)
|
||||
|
||||
score = str(self.score).zfill(6)
|
||||
lines = str(self.stack.lines_completed_count).zfill(4)
|
||||
level = str(self.get_level()).zfill(2)
|
||||
|
||||
TextGenerator.draw("Top", (80, 120), self.screen)
|
||||
TextGenerator.draw("000000", (80, 140), self.screen)
|
||||
TextGenerator.draw("Score", (80, 180), self.screen)
|
||||
TextGenerator.draw("000000", (80, 200), self.screen)
|
||||
TextGenerator.draw("Lines 0000", (300, 40), self.screen)
|
||||
TextGenerator.draw(score, (80, 200), self.screen)
|
||||
TextGenerator.draw("Lines " + lines, (300, 40), self.screen)
|
||||
TextGenerator.draw("Next", (600, 120), self.screen)
|
||||
TextGenerator.draw("LVL 00", (600, 220), self.screen)
|
||||
TextGenerator.draw("LVL " + level, (600, 220), self.screen)
|
||||
|
||||
# update display
|
||||
pygame.display.update()
|
||||
|
||||
def get_level(self) -> int:
|
||||
lines_per_level = ConfigurationManager.get("engine", "lines-per-level")
|
||||
return 0 if not self.stack else self.stack.lines_completed_count // lines_per_level
|
||||
|
||||
|
||||
Reference in New Issue
Block a user