-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.py
445 lines (402 loc) · 12.4 KB
/
classes.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
import pygame
# from game import EFFECT_SOUND
SCREEN_WIDTH = 540
SCREEN_HEIGHT = 960
SCREEN = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0,0,255)
YELLOW = (255,255,0)
PURPLE = (255,0,255)
BLACK = (0,0,0)
WHITE = (255,255,255)
LIGHTGRAY = (180,180,180)
DARKGRAY = (127,127,127)
pygame.mixer.init()
'''
sound는 3개의 원소를 가진 tuple로 쓰기로 한다
a_sound = (pygame.mixer.Sound(), default sound volumn, sound type)
default sound volumn: (0 ~ 1)
sound type: 0 -> music, 1 -> effect
'''
# from https://pixabay.com/ko/music/search/genre/%EB%B9%84%EB%94%94%EC%98%A4%20%EA%B2%8C%EC%9E%84/
background_sound = (pygame.mixer.Sound('files/sound/bgm.mp3'), 0.3, 0)
# from https://pixabay.com/ko/sound-effects/search/arcade/
game_sound = (pygame.mixer.Sound('files/sound/game_sound.mp3'),1, 0)
# from https://freesound.org/people/tyops/sounds/562770/
ee_sound = (pygame.mixer.Sound('files/sound/ee_sound.mp3'),1, 0)
# from https://freesound.org/people/MATRIXXX_/sounds/349873/
drop_sound = (pygame.mixer.Sound('files/sound/drop_sound.wav'),1, 1)
# from https://pixabay.com/ko/sound-effects/search/game%20success/
recommend_sound = (pygame.mixer.Sound('files/sound/recommend_sound.wav'), 0.7, 1)
# from https://pixabay.com/sound-effects/search/level/
win_sound = (pygame.mixer.Sound('files/sound/win_sound.mp3'), 0.5, 1)
# from https://pixabay.com, but I'm not sure what is the exact address.
draw_sound = (pygame.mixer.Sound('files/sound/draw_sound.wav'), 0.5, 1)
# from https://pixabay.com/ko/sound-effects/search/booing/
fail_sound = (pygame.mixer.Sound('files/sound/lose_sound.mp3'), 0.7, 1)
# from https://pixabay.com/ko/sound-effects/search/arcade/
button_sound = (pygame.mixer.Sound('files/sound/button_sound.mp3'), 0.3, 1)
# from https://pixabay.com/ko/sound-effects/search/pop/
undo_sound = (pygame.mixer.Sound('files/sound/undo_sound.mp3'), 0.5, 1)
# from https://pixabay.com/ko/sound-effects/search/boop/
select_color_sound = (pygame.mixer.Sound('files/sound/select_color_sound.mp3'), 0.7, 1)
# from https://pixabay.com/ko/sound-effects/search/xylophone/
do = (pygame.mixer.Sound('files/sound/xylophone_do.mp3'), 1, 1)
mi = (pygame.mixer.Sound('files/sound/xylophone_mi.mp3'), 1, 1)
sol = (pygame.mixer.Sound('files/sound/xylophone_sol.mp3'), 1, 1)
high_do = (pygame.mixer.Sound('files/sound/xylophone_do2.mp3'), 1, 1)
connect4_sound = [do, mi, sol, high_do]
# main_font from https://campaign.naver.com/nanumsquare_neo/#download
# monospace_font from https://github.com/naver/d2codingfont/releases/tag/VER1.3.2
class Button:
def __init__(self, name, cx=0,cy=0,width=100,height=100,color=WHITE, font=None, font_size=30):
self.name = name
self.cx = cx
self.cy = cy
self.width = width
self.height = height
self.color = color
self.clicked = False
self.clicked_color = LIGHTGRAY
if font is None:
self.font = pygame.font.Font('files/font/main_font.ttf', font_size)
else: self.font = font
self.change_text_color()
def draw_and_get_event(self, surface, event):
x = self.cx-self.width/2
y = self.cy-self.height/2
# print(self.x,self.y, self.width, self.height)
mouse_pos = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
# print(click)
border = pygame.draw.rect(surface,self.color, (x,y,self.width,self.height))
if x+self.width > mouse_pos[0] > x and y+self.height > mouse_pos[1] > y:
if event is not None:
if event.type == pygame.MOUSEBUTTONDOWN:
self.clicked_color = DARKGRAY
self.clicked = True
elif event.type == pygame.MOUSEBUTTONUP:
if self.clicked:
self.clicked = False
self.clicked_color = LIGHTGRAY
return True
else:
self.clicked = False
pygame.draw.rect(surface, self.clicked_color,(x,y,self.width,self.height))
# if click[0] == 1:
# print(click)
# return True
elif self.clicked:
if event.type == pygame.MOUSEBUTTONUP:
self.clicked = False
self.clicked_color = LIGHTGRAY
pygame.draw.rect(surface, self.clicked_color,(x,y,self.width,self.height))
else:
pygame.draw.rect(surface,self.color, (x,y,self.width,self.height))
text = self.font.render(self.name, True, self.text_color)
text_rect = text.get_rect(center=(surface.get_width()/2, surface.get_height()/2))
text_rect.center = border.center
surface.blit(text, text_rect)
return False
def change_color(self, color):
self.color = color
self.change_text_color()
def change_text_color(self):
r,g,b = self.color
luma = 0.2126 * r + 0.7152 * g + 0.0722 * b # per ITU-R BT.709
# print("luma:",luma)
if luma < 127.5: self.text_color=WHITE
else: self.text_color=BLACK
# color picker ver. 1
# color_picker = (
# (255, 0, 0), # - 빨간색
# (0, 255, 0), # - 초록색
# (0, 0, 255), # - 파란색
# (255, 255, 0), # - 노란색
# (255, 0, 255), # - 마젠타
# (0, 255, 255), # - 시안
# (10, 10, 10), # - 검은색
# (0, 128, 0), # - 어두운 초록색
# (0, 0, 128), # - 어두운 파란색
# (128, 128, 0), # - 어두운 노란색
# (128, 0, 128), # - 어두운 보라색
# (0, 128, 128), # - 어두운 청녹색
# (192, 0, 0), # - 선명한 빨간색
# (0, 192, 0), # - 선명한 초록색
# (0, 0, 192), # - 선명한 파란색
# (255, 128, 0), # - 주황색
# (255, 0, 128), # - 로즈
# (128, 255, 0), # - 라임
# (0, 255, 128), # - 민트
# (128, 0, 255), # - 보라
# (0, 128, 255), # - 하늘색
# (255, 128, 128), # - 연한 빨간색
# (128, 255, 128), # - 연한 초록색
# (128, 128, 255), # - 연한 파란색
# (255, 255, 153), # - 레몬
# (153, 255, 255), # - 아쿠아
# (255, 102, 255), # - 핑크
# (153, 153, 255), # - 라벤더
# (57, 255, 20), # - 밝은 라임
# (255, 140, 105), # - 살구색
# (51, 153, 255), # - 코너플라워 블루
# (153, 255, 51), # - 샤르트루즈 그린
# (255, 80, 147), # - 핫 핑크
# (102, 51, 153), # - 임페리얼 퍼플
# (244, 164, 96), # - 살구석
# (128, 222, 234), # - 파우더 블루
# (227, 11, 92), # - 자몽
# (153, 102, 51), # - 밤색
# (246, 173, 198), # - 연분홍
# (85, 107, 47), # - 올리브 드라브
# (216, 191, 216), # - 시스
# (65, 105, 225), # - 로열 블루
# )
# color picker ver. 2
color_picker = (
(0, 0, 128),
(0, 42, 128),
(0, 85, 128),
(0, 127, 128),
(0, 170, 128),
(0, 212, 128),
(0, 255, 128),
(51, 0, 128),
(51, 42, 128),
(51, 85, 128),
(51, 127, 128),
(51, 170, 128),
(51, 212, 128),
(51, 255, 128),
(102, 0, 128),
(102, 42, 128),
(102, 85, 128),
(102, 127, 128),
(102, 170, 128),
(102, 212, 128),
(102, 255, 128),
(153, 0, 128),
(153, 42, 128),
(153, 85, 128),
(153, 127, 128),
(153, 170, 128),
(153, 212, 128),
(153, 255, 128),
(204, 0, 128),
(204, 42, 128),
(204, 85, 128),
(204, 127, 128),
(204, 170, 128),
(204, 212, 128),
(204, 255, 128),
(255, 0, 128),
(255, 42, 128),
(255, 85, 128),
(255, 127, 128),
(255, 170, 128),
(255, 212, 128),
(255, 255, 128)
)
ee_boards = (
(
(2,2,2,2,2,2,2),
(2,2,1,1,1,2,2),
(2,2,1,2,1,2,2),
(2,2,1,1,1,2,2),
(2,2,2,1,2,2,2),
(2,2,1,1,1,2,2)
),
(
(2,2,1,1,1,2,2),
(2,2,1,2,2,2,2),
(2,2,1,1,1,2,2),
(2,2,2,2,2,2,2),
(2,2,1,1,1,2,2),
(2,2,2,1,2,2,2)
),
(
(2,2,2,2,2,2,2),
(2,2,2,2,2,2,2),
(2,2,1,2,2,2,1),
(2,2,1,2,2,1,1),
(2,2,1,2,2,2,1),
(2,2,1,1,1,2,1)
),
(
(2,2,1,1,1,2,2),
(2,2,1,2,1,2,2),
(2,2,1,1,1,2,2),
(2,2,2,2,2,2,2),
(2,2,1,1,1,2,2),
(2,2,2,1,2,2,2)
),
(
(2,2,2,2,2,2,2),
(2,2,2,2,2,2,2),
(2,2,1,1,1,1,2),
(2,2,2,2,2,1,2),
(2,2,2,1,2,2,2),
(2,2,1,1,1,1,2),
),
(
(2,2,2,2,2,2,2),
(2,2,2,2,2,2,2),
(2,1,1,1,2,1,2),
(2,1,2,1,2,1,1),
(2,1,1,1,2,1,2),
(2,2,2,2,2,1,2)
),
(
(2,2,1,2,2,2,2),
(2,1,2,1,2,2,2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