summaryrefslogtreecommitdiff
path: root/src/sliceitoff/game/game.py
blob: bcb04e70ce81a5fba18bee445ea1c8d4c53943bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
""" Slice It Off! - Game where you slice the area where enemies reside to
    the minimum
"""

from pathlib import Path

import pygame

from display import Display
from text import Fonts
from stats import Stats
from screens import welcome_screen, hiscores_screen
from hiscores import HiScores

from .level import Level
from .show import Show
from .initials import Initials

class Game:
    def __init__(self):
        pygame.init()
        self.clock = pygame.time.Clock()
        self.display = Display()
        self.stats = None
        self.hiscores = HiScores()
        Fonts.load_fonts( Path(__file__).parent.parent.resolve() )
        pygame.mouse.set_visible(False)

    def welcome(self):
        ws = Show(welcome_screen())
        dt = 0
        while ws.active:
            ws.update(dt = self.clock.tick())
            self.display.update( [ws] )

    def show_highscores(self):
        his = Show(hiscores_screen(str(self.hiscores)))
        dt = 0
        while his.active:
            his.update(dt = self.clock.tick())
            self.display.update( [his] )

    def newgame(self):
        self.stats = Stats()
        while self.stats.lives:
            level = Level(display = self.display, stats = self.stats)
            dt = 0
            while level.step(dt):
                dt = self.clock.tick()
            if self.stats.lives:
                self.stats.level_up()

    def initials(self):
        initials = Initials()
        dt = 0
        while initials.active:
            initials.update(dt = self.clock.tick())
            self.display.update([initials])
        return initials.name

    def run(self):
        self.welcome()
        self.newgame()
        if self.hiscores.high_enough(self.stats.score):
            self.hiscores.add( self.stats.score, self.initials())
        self.show_highscores()
        
    
    def __del__(self):
        pygame.quit()