-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfunctions.py
57 lines (46 loc) · 1.54 KB
/
functions.py
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
import pygame
class Fucntions:
def __init__(self, st, screen):
self.st = st
self.screen = screen
def show_score(self, score):
surface = None
adjust = True # at least calculate surface once
while adjust:
text = self.st.score + str(score)
font = pygame.font.SysFont(self.st.score_font, self.st.score_size)
surface = font.render(text, True, self.st.score_color)
# adjust score font when it is too big
adjust = ((surface.get_width() + 2 * self.st.score_pos[0]) > self.st.func_size[0])
if adjust:
self.st.score_size -= self.st.score_font_adjust
self.screen.blit(surface, self.st.score_pos)
class Status:
def __init__(self):
# some numbers
self.GAMEOVER = 0x0
self.NEWSTART = 0x1
self.ACTIVE = 0x2
self.RENEW = 0x3
# game status
self.game_status = self.NEWSTART
self.refresh()
def is_game_active(self):
return self.game_status == self.ACTIVE
def is_game_over(self):
return self.game_status == self.GAMEOVER
def is_game_new(self):
return self.game_status == self.NEWSTART
def is_game_renew(self):
return self.game_status == self.RENEW
def is_AI(self):
return self.AI
def refresh(self):
self.left = False
self.right = False
self.down = False
self.rotate = False
self.straight_drop = False
self.AI = False
# score status
self.score = 0