-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscores.py
More file actions
63 lines (51 loc) · 1.77 KB
/
scores.py
File metadata and controls
63 lines (51 loc) · 1.77 KB
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
'''
Things about scores.
'''
import time
import pygame
import sysfiles
def safe(b):
return 0 if b < 0 else (255 if b > 255 else b)
class ScoreEvent:
texts = [
"无事发生",
"消除{}行",
"合成{}",
"{}行救场", # Clear lines when there is block at very top
"清理大师" # Leave <=1 row behind
]
MaxTime = 20.0
font = pygame.font.Font(sysfiles.hanFont(), 36)
def __init__(self, message, value, param):
self.message = message
self.value = value
self.param = param
self.timeout = ScoreEvent.MaxTime + time.time()
def getText(self):
return ScoreEvent.texts[self.message].format(self.param) + ' +' + str(self.value)
def __str__(self):
return self.getText()
def getMult(self):
return (self.timeout - time.time()) / ScoreEvent.MaxTime * 0.5 + 0.5
def getColor(self):
return (safe(int(255 * self.getMult())), safe(int(255 * self.getMult() ** 2)), 0)
def draw(self, DISP, pos): # pos = 0, 1, ..., maxEvents
btext = ScoreEvent.font.render(self.getText(), True, self.getColor())
btextrect = btext.get_rect()
btextrect.topleft = (750, 350 + 40 * pos)
DISP.blit(btext, btextrect)
class ScoreBoard:
maxEvents = 10
def __init__(self):
self.events = []
def clear(self):
self.events = []
def draw(self, DISP):
for idx, x in enumerate(self.events):
x.draw(DISP, idx)
def addEvent(self, message, value, param):
self.events.append(ScoreEvent(message, value, param))
if len(self.events) > self.maxEvents:
self.events.pop(0)
def refresh(self):
self.events = [x for x in self.events if x.timeout > time.time()]