summaryrefslogtreecommitdiff
path: root/src/sliceitoff/game/hiscore.py
blob: 734ad5e0a288fb89248c7954b5ab8dcc6701eeea (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
import pygame

from screens import hiscore_screen

class HiScore(pygame.sprite.Group):
    def __init__(self):
        super().__init__()
        self.add(hiscore_screen(""))
        self.name = ""
        
    def update(self, **kwargs):
        super().update(**kwargs)

    def step(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            if event.type == pygame.KEYDOWN:
                if event.key in (
                        pygame.K_ESCAPE,
                        pygame.K_KP_ENTER,
                        pygame.K_RETURN):
                    return False
                if event.key in (
                        pygame.K_RSHIFT,
                        pygame.K_LSHIFT,
                        pygame.K_RCTRL,
                        pygame.K_LCTRL,
                        pygame.K_RALT,
                        pygame.K_LALT,
                        pygame.K_RMETA,
                        pygame.K_LMETA,
                        pygame.K_LSUPER,
                        pygame.K_RSUPER,
                        pygame.K_SPACE):
                    continue
                if event.key in (pygame.K_BACKSPACE, pygame.K_DELETE):
                    self.name = self.name [:-1]
                elif pygame.key.name(event.key):
                    self.name += pygame.key.name(event.key)[0].upper()
                    self.name = self.name[:8]
        self.empty()
        self.add(hiscore_screen(self.name))
        return True