-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstorymodegame1.py
More file actions
1350 lines (1089 loc) · 62.6 KB
/
storymodegame1.py
File metadata and controls
1350 lines (1089 loc) · 62.6 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
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import pygame
import sys
import storymode2
import loadcard
import shuffle
from loadcard import Card
import Computerplay
from config import Configset
import pause
import achievement
import datetime
import json
pygame.init()
def load_custom_keys():
global custom_keys
with open('keySetting.json', 'r') as f:
custom_keys = json.load(f)
def show_color_popup(screen, width, height, font, colors, color_values):
rects = []
popup_x = (screen.get_width() - width) // 2
popup_y = (screen.get_height() - height) // 2
for i in range(4):
rect_x = popup_x + 20 + i * 120
rect_y = popup_y + 25
rect = pygame.Rect(rect_x, rect_y, 50, 50)
rects.append(rect)
pygame.draw.rect(screen, color_values[i], rect)
color_text = font.render(colors[i], True, (0, 0, 0))
color_text_rect = color_text.get_rect(center=rect.center)
screen.blit(color_text, color_text_rect)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = pygame.mouse.get_pos()
for i, rect in enumerate(rects):
if rect.collidepoint(mouse_pos):
return colors[i]
def change_turn(playDirection, numPlayers, playerTurn):
# 턴 이동
playerTurn += playDirection
if playerTurn == numPlayers:
playerTurn = 0
elif playerTurn < 0:
playerTurn = numPlayers - 1
return playerTurn
# 텍스트 생성 함수
def render_timer():
current_time = datetime.datetime.now()
time_left = end_time - current_time
if time_left.total_seconds() <= 0:
text = bold_font.render("Time's up!", True, (255, 0, 0))
else:
seconds_left = int(time_left.total_seconds())
text = font.render(str(seconds_left), True, (0, 0, 0))
text_rect = text.get_rect(center=(timer_x + timer_width / 2, timer_y + timer_height / 2))
section3.blit(text, text_rect)
def next_draw(numPlayers, playDirection, playerTurn):
playerDraw = playerTurn + playDirection
if playerDraw == numPlayers:
playerDraw = 0
elif playerDraw < 0:
playerDraw = numPlayers - 1
return playerDraw
def start_game():
# 카드뽑기 함수, top에서
def drawCards(numCards):
cardsDrawn = []
for x in range(numCards):
cardsDrawn.append(card.pop(0))
return cardsDrawn
# 플레이어가 플레이 가능한지 판단, 버린카드보고
def canPlay(colour, value, playerHand):
for card in playerHand:
if "Black" in card:
return True
elif colour in card or value in card:
return True
return False
# 플레이어 낸카드 가능한건지 체크하기
def check_card(colour, value, sprite):
name = sprite.get_name()
name = name.split('_')
if name[0] == 'BLACK':
return True
elif name[0] == colour:
return True
elif name[1] == value:
return True
else:
return False
# 버리는카드
discards = []
colours = ["RED", "GREEN", "YELLOW", "BLUE"]
# 플레이어
players = []
# 플레이어 인원 입력받기
# 일단 7명으로 임의로 지정
numPlayers = 2
# 플레이어 점수
playerscore = []
for i in range(numPlayers):
playerscore.append(0)
# 덱만들고 섞기
unodeck = shuffle.UNODeck()
temp = unodeck.storyshuffle()
for hand in temp:
players.append(hand)
card = unodeck.getCards()
# 이전 저장파일 불러오기
cf = Configset()
default = cf.getChange()
screen_width = int(default[0])
screen_height = int(default[1])
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("UNO Game")
achiev = achievement.Achievement()
# 다음 턴
playerTurn = 0
turn = 0
# 시계방향1 반시계방향 -1
playDirection = 1
# Set up 유저 카드
selected_item = 0
# 처음 카드 1장 버리기
discards.append(card.pop(0))
# 와일드 드로우 4인거 체크하기
while discards[-1] == 'BLACK_DRAW4':
card.append(discards.pop(0))
discards.append(card.pop(0))
splitCard = discards[-1].split("_", 1)
# 처음 카드색
curruntcolour = splitCard[0]
if curruntcolour != "BlACK":
cardVal = splitCard[1]
else:
cardVal = "Any"
# 승자
winner = -1
# '배경1.mp3' 파일 재생
pygame.mixer.music.load('./이채은/sound/배경1.mp3')
pygame.mixer.music.play(-1)
'''
# 전체화면 설정
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("UNO Game")
'''
# 색 정의
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
LIGHT_PINK = (255, 182, 193)
GRAY = (128, 128, 128)
RED = (255, 0, 0)
GREEN = (0, 255, 0) # 녹색 추가
LIGHT_YELLOW = (255, 255, 153)
# 섹션1 크기, 테두리 설정, 배경사진'background.png'
section1_width = int(screen_width * 0.80)
section1_height = int(screen_height * 0.60)
section1 = pygame.Surface((section1_width, section1_height))
background = pygame.image.load('./이채은/image/singleBG_c.png')
background = pygame.transform.scale(background, (section1_width, section1_height))
section1.blit(background, (0, 0, 10, 10))
pygame.draw.rect(section1, LIGHT_YELLOW, (0, 0, section1_width, section1_height), 3)
'''
# 현재 색 표시 칸 구현
pygame.draw.circle(section1, WHITE, (int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
pygame.draw.circle(section1, LIGHT_YELLOW, (int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 3)
pygame.draw.circle(section1, GREEN, (int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
'''
# 현재 색 표시 칸 구현
if curruntcolour == 'BLUE':
pygame.draw.circle(section1, BLUE,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'RED':
pygame.draw.circle(section1, RED,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'YELLOW':
pygame.draw.circle(section1, LIGHT_YELLOW,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'GREEN':
pygame.draw.circle(section1, GREEN,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
# Inside your game loop where you want to draw the text
len(card)
font = pygame.font.Font(None, 24)
card_count_text = str(len(card)) # convert the card count to string
text_surface = font.render(card_count_text, True, BLACK) # render the text
text_rect = text_surface.get_rect(
center=(int(section1_width * 0.8), int(section1_height * 0.45))) # get the rect for positioning
section1.blit(text_surface, text_rect) # draw the text to the section1 surface
pygame.display.update()
# 색 표시 기능 구현
# 섹션2 크기, 배경색, 테두리 설정
section2_width = int(screen_width * 0.25)
section2_height = screen_height
section2 = pygame.Surface((section2_width, section2_height))
section2.fill((LIGHT_YELLOW))
pygame.draw.rect(section2, LIGHT_YELLOW, (0, 0, section2_width, section2_height), 3)
# 플레이어별 위치 구현
p_width = int(section2_width / 1.0) # Width of each rectangle, slightly smaller than section2
p_height = int((section2_height - 10) / 6) # Height of each rectangle, spaced apart by 2
p_spacing = 3 # Spacing between rectangles
p1_rect = pygame.Rect((section2_width - p_width) / 2, p_spacing, p_width * 0.789, p_height)
p2_rect = pygame.Rect((section2_width - p_width) / 2, p_height + p_spacing * 2, p_width * 0.789, p_height)
p3_rect = pygame.Rect((section2_width - p_width) / 2, p_height * 2 + p_spacing * 3, p_width * 0.789, p_height)
p4_rect = pygame.Rect((section2_width - p_width) / 2, p_height * 3 + p_spacing * 4, p_width * 0.789, p_height)
p5_rect = pygame.Rect((section2_width - p_width) / 2, p_height * 4 + p_spacing * 5, p_width * 0.789, p_height)
p6_rect = pygame.Rect((section2_width - p_width) / 2, p_height * 5 + p_spacing * 6, p_width * 0.789, p_height)
# p에 모두 'se2.png' 이미지 띄우기
se2 = pygame.image.load('./이채은/image/se2.png')
se2 = pygame.transform.scale(se2, (int(p_width * 0.789), int(p_height)))
section2.blit(se2, (p1_rect.x, p1_rect.y, 10, 10))
section2.blit(se2, (p2_rect.x, p2_rect.y, 10, 10))
section2.blit(se2, (p3_rect.x, p3_rect.y, 10, 10))
section2.blit(se2, (p4_rect.x, p4_rect.y, 10, 10))
section2.blit(se2, (p5_rect.x, p5_rect.y, 10, 10))
section2.blit(se2, (p6_rect.x, p6_rect.y, 10, 10))
# 섹션2 플레이어별 이름 표시
font = pygame.font.SysFont('comicsansms', 18)
text = font.render('Player1', True, BLACK)
section2.blit(text, (p1_rect.x + 10, p1_rect.y + 10, 10, 10))
# 섹션3 크기, 배경색, 테두리 설정
section3_width = section1_width
section3_height = int(screen_height * 0.40)
section3 = pygame.Surface((section3_width, section3_height))
section3.fill((255, 255, 255))
pygame.draw.rect(section3, LIGHT_YELLOW, (0, 0, section3_width, section3_height), 3)
# 섹션3 우측 상단에 타이머 표시 칸 구현
timer_width = int(section3_width * 0.05)
timer_height = int(section3_height * 0.25)
timer_x = section3_width - timer_width - 15
timer_y = 10
# 섹션3 우측 상단에 타이머 표시 칸 안에 "0" 텍스트 생성
font = pygame.font.SysFont('comicsansms', 20)
bold_font = pygame.font.SysFont('comicsansms', 15, bold=True)
text = font.render("0", True, RED)
text_rect = text.get_rect(center=(timer_x + timer_width / 2, timer_y + timer_height / 2))
section3.blit(text, text_rect)
'''
# 섹션3 좌측 상단에 "Your turn" 텍스트 생성
font = pygame.font.SysFont('comicsansms', 20)
if playerTurn == 0:
text = font.render("Your turn", True, BLACK)
else:
text = font.render("{}'s turn".format(playerTurn), True, BLACK)
text_rect = text.get_rect(center=(int(section3_width * 0.1), int(section3_height * 0.1)))
section3.blit(text, text_rect)
'''
# 섹션3 좌측 상단에 "Your turn" 텍스트 생성
font = pygame.font.SysFont('comicsansms', 20)
if playerTurn == 0:
text = font.render("Your turn", True, BLACK)
else:
text = font.render("{}'s turn".format(playerTurn), True, BLACK)
text_rect = text.get_rect(center=(int(section3_width * 0.1), int(section3_height * 0.1)))
# Draw a rectangle with white color as background
background_rect = pygame.Rect(text_rect.left - 10, text_rect.top - 10, text_rect.width + 20,
text_rect.height + 20) # create a larger rect for the background
pygame.draw.rect(section3, WHITE, background_rect) # draw the rect to the section3 surface
# Now draw the text
section3.blit(text, text_rect)
pygame.display.update()
# "UNO!" 텍스트 생성
font = pygame.font.SysFont('comicsansms', 20)
bold_font = pygame.font.SysFont('comicsansms', 15, bold=True)
text = font.render("UNO!", True, BLACK)
text_rect = text.get_rect(center=(int(section3_width * 0.23), int(section3_height * 0.1)))
pygame.draw.rect(section3, RED, (text_rect.x - 5, text_rect.y - 5, text_rect.width + 10, text_rect.height + 10), 3)
section3.blit(text, text_rect)
# 색상 변경 사각형 및 텍스트 생성
colors = ["RED", "YELLOW", "BLUE", "GREEN"]
color_values = [(255, 0, 0), (255, 255, 0), (0, 0, 255), (0, 255, 0)]
rects = []
'''
for i in range(4):
rect_x = text_rect.right + 50 + i * 90
rect_y = text_rect.centery - 25
rect = pygame.Rect(rect_x, rect_y, 50, 50)
rects.append(rect)
pygame.draw.rect(section3, color_values[i], rect)
color_text = font.render(colors[i], True, BLACK)
color_text_rect = color_text.get_rect(center=rect.center)
section3.blit(color_text, color_text_rect)
pygame.display.update()
'''
##섹션3 우측 중앙에 마지막 한장 남았을때 누르는 버튼 구현
# UNO_bt = pygame.image.load('./이채은/image/UNO_bt.png')
# UNO_bt = pygame.transform.scale(UNO_bt, (150,110))
# section3.blit(UNO_bt, (int(section3_width*0.72), int(section3_height*0.2), 10, 10))
##섹션3 우측 중앙에 마지막 한장 남았을때 누르는 버튼 구현
# UNO_bt = pygame.image.load('./이채은/image/UNO_bt.png')
# UNO_bt = pygame.transform.scale(UNO_bt, (150,110))
# section3.blit(UNO_bt, (int(section3_width*0.72), int(section3_height*0.2), 10, 10))
screen.blit(section1, (0, 0))
screen.blit(section2, (section1_width, 0))
screen.blit(section3, (0, section1_height))
pygame.display.update()
# 게임 시작할 때
# 유저 카드 그리기
selected_card = 0 # 선택된 카드의 인덱스
user_card = []
for item in players[0]:
cards = Card(item, (screen_width, screen_height))
user_card.append(cards)
i = 0
temp_list = []
for item in user_card:
# item.update((50 + (screen_width / 10) * i, (screen_height * 0.35) / 2))
item.update((50 + 50 * i, 500))
if i == selected_card: # 선택된 카드에 대한 시각적 표시 (예: 선택된 카드를 약간 위로 올림)
item.update((50 + 50 * i, 470))
temp_list.append(item)
i += 1
user_group = pygame.sprite.RenderPlain(*temp_list)
user_group.draw(screen) # 그리기
# 백 카드 스프라이트로 시도하기
backcard = Card('BACK', (screen_width, screen_height))
backcard.transform(160, 150)
backcard.update((int(section1_width * 0.20), int(section1_height * 0.45)))
backcard = pygame.sprite.RenderPlain(backcard)
backcard.draw(screen)
# 컴퓨터 카드 그리기
for j in range(1, numPlayers):
temp_list = []
i = 0
for item in players[j]: # player_deck 해당 컴퓨터의 카드 리스트
cards = Card('BACK', (1200, 500))
cards.transform(30, 40)
cards.update((810 + 100 / len(players[1]) * i, 105 * j - 50))
temp_list.append(cards)
i += 1
player_group = pygame.sprite.RenderPlain(*temp_list)
player_group.draw(screen)
pygame.display.update()
# top카드 이미지 변화
back = pygame.image.load('./최회민/img/{}.png'.format(discards[-1]))
back = pygame.transform.scale(back, (128, 162))
x = int(screen_width * 0.4)
y = int(screen_height * 0.4)
screen.blit(back, (300, 110, 10, 10))
# section1.blit(back, (300, 110, 10, 10))
pygame.display.update()
pygame.display.flip()
# 팝업창 폰트 지정
font = pygame.font.SysFont('comicsansms', 20)
running = True
# 게임 루프 실행
while running:
load_custom_keys()
# 0번 플레이어로 하고 나머지 컴퓨터로 하기
# 컴퓨터인 경우 먼저하기
if playerTurn != 0:
pygame.time.wait(700)
print("top ", discards[-1], "player turn", playerTurn + 1)
# 이함수 hand넘겨받는기능추가필요
unoplayer = Computerplay.UnoPlayer(players[playerTurn])
res = unoplayer.storyAplay(discards[-1], curruntcolour)
# 컴퓨터 낼수 없는경우
if res == None:
players[playerTurn].extend(drawCards(1))
# 1장 추가되는거 이미지로 구현
# 턴 변화
playerTurn = change_turn(playDirection, numPlayers, playerTurn)
turn += 1
# 화면다시 그리기
screen.blit(section3, (0, section1_height))
# 플레이어 카드 변화
for i, item in enumerate(user_group):
if i == selected_card: # 선택된 카드에 대한 시각적 표시 (예: 선택된 카드를 약간 위로 올림)
item.update((50 + 50 * i, 470))
else:
item.update((50 + 50 * i, 500))
user_group.draw(screen)
pygame.display.update()
# 섹션3 좌측 상단에 "Your turn" 텍스트 생성
font = pygame.font.SysFont('comicsansms', 20)
if playerTurn == 0:
text = font.render("Your turn", True, BLACK)
else:
text = font.render("{}'s turn".format(playerTurn), True, BLACK)
text_rect = text.get_rect(center=(int(section3_width * 0.1), int(section3_height * 0.1)))
# Draw a rectangle with white color as background
background_rect = pygame.Rect(text_rect.left - 10, text_rect.top - 10, text_rect.width + 20,
text_rect.height + 20) # create a larger rect for the background
pygame.draw.rect(section3, WHITE, background_rect) # draw the rect to the section3 surface
# Now draw the text
section3.blit(text, text_rect)
pygame.display.update()
screen.blit(section1, (0, 0))
# 백 카드 스프라이트로 시도하기
backcard = Card('BACK', (screen_width, screen_height))
backcard.transform(160, 150)
backcard.update((int(section1_width * 0.20), int(section1_height * 0.45)))
backcard = pygame.sprite.RenderPlain(backcard)
backcard.draw(screen)
# top카드 이미지 변화
back = pygame.image.load('./최회민/img/{}.png'.format(discards[-1]))
back = pygame.transform.scale(back, (128, 162))
x = int(screen_width * 0.4)
y = int(screen_height * 0.4)
screen.blit(back, (300, 110, 10, 10))
# section1.blit(back, (300, 110, 10, 10))
pygame.display.update()
# 현재 색 표시 칸 구현
if curruntcolour == 'BLUE':
pygame.draw.circle(section1, BLUE,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'RED':
pygame.draw.circle(section1, RED,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'YELLOW':
pygame.draw.circle(section1, LIGHT_YELLOW,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'GREEN':
pygame.draw.circle(section1, GREEN,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
# Inside your game loop where you want to draw the text
len(card)
font = pygame.font.Font(None, 24)
card_count_text = str(len(card)) # convert the card count to string
text_surface = font.render(card_count_text, True, BLACK) # render the text
text_rect = text_surface.get_rect(
center=(
int(section1_width * 0.8), int(section1_height * 0.45))) # get the rect for positioning
section1.blit(text_surface, text_rect) # draw the text to the section1 surface
pygame.display.update()
pygame.display.update()
else:
# 컴퓨터 낼수 있는경우
discards.append(res)
# 이거 이미 컴퓨터 메소드 호출시 삭제해준다
# players[playerTurn].remove(res)
# 컴퓨터도 카드 내서 카드 수 감소하는거 구현필요
# if len(players[playerTurn]) == 1:
# 컴퓨터 우노구현
# 컴퓨터 승리조건
if len(players[playerTurn]) == 0:
running = False
print("finish")
text = font.render("{}'s win! continue : enter".format(playerTurn), True, BLACK)
text_rect = text.get_rect(center=(int(screen_width * 0.3), int(screen_height * 0.5)))
screen.blit(text, text_rect)
pygame.display.update()
# enter key 누르면 게임 종료
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == custom_keys['return']:
return
else:
# 버린카드 특별카드 체크
splitCard = discards[-1].split("_", 1)
curruntcolour = splitCard[0]
# 와일드면 카드값에 any부여
if curruntcolour == "BLACK":
cardVal = "Any"
else:
cardVal = splitCard[1]
# 와읻드면 색 선택하게
if curruntcolour == "BLACK":
unoplayer = Computerplay.UnoPlayer(players[playerTurn])
newColour = unoplayer.choose_color(players[playerTurn])
curruntcolour = newColour
# 리버스면 다음턴 회전반대로
if cardVal == "REVERSE":
playDirection = playDirection * (-1)
if len(players) == 2:
playerTurn = change_turn(playDirection, numPlayers, playerTurn)
# 스킵하기
elif cardVal == "SKIP":
playerTurn = change_turn(playDirection, numPlayers, playerTurn)
# 2장 뽑기
elif splitCard[1] == "DRAW2":
playerDraw = next_draw(numPlayers, playDirection, playerTurn)
players[playerDraw].extend(drawCards(2))
# 플레이어면 유저그룹 변하게
if playerDraw == 0:
# 화면다시 그리기
screen.blit(section3, (0, section1_height))
for i in range(2):
tmp = Card(players[playerDraw][len(players[playerDraw]) - 2 + i], (800, 600))
user_group.add(tmp)
# 플레이어 카드 변화
for i, item in enumerate(user_group):
if i == selected_card: # 선택된 카드에 대한 시각적 표시 (예: 선택된 카드를 약간 위로 올림)
item.update((50 + 50 * i, 470))
else:
item.update((50 + 50 * i, 500))
user_group.draw(screen)
pygame.display.update()
# 어게인
elif splitCard[1] == "AGAIN":
playDirection = playDirection * (-1)
playerTurn = change_turn(playDirection, numPlayers, playerTurn)
playDirection = playDirection * (-1)
# 색 체인지
elif splitCard[1] == "CHANGE":
unoplayer = Computerplay.UnoPlayer(players[playerTurn])
newColour = unoplayer.choose_color(players[playerTurn])
curruntcolour = newColour
# 와일드 드로우 4
elif splitCard[1] == "DRAW4":
playerDraw = next_draw(numPlayers, playDirection, playerTurn)
players[playerDraw].extend(drawCards(4))
# 플레이어면 유저그룹 변하게
if playerDraw == 0:
# 화면다시 그리기
screen.blit(section3, (0, section1_height))
for i in range(4):
tmp = Card(players[playerDraw][len(players[playerDraw]) - 4 + i], (800, 600))
user_group.add(tmp)
# 플레이어 카드 변화
# 플레이어 카드 변화
for i, item in enumerate(user_group):
if i == selected_card: # 선택된 카드에 대한 시각적 표시 (예: 선택된 카드를 약간 위로 올림)
item.update((50 + 50 * i, 470))
else:
item.update((50 + 50 * i, 500))
user_group.draw(screen)
pygame.display.update()
# 컴퓨터 카드변화
screen.blit(section2, (section1_width, 0))
# 컴퓨터 카드 그리기
for j in range(1, numPlayers):
temp_list = []
i = 0
for item in players[j]: # player_deck 해당 컴퓨터의 카드 리스트
cards = Card('BACK', (1200, 500))
cards.transform(30, 40)
cards.update((810 + 100 / len(players[1]) * i, 105 * j - 50))
temp_list.append(cards)
i += 1
player_group = pygame.sprite.RenderPlain(*temp_list)
player_group.draw(screen)
pygame.display.update()
# 턴 변화
playerTurn = change_turn(playDirection, numPlayers, playerTurn)
turn += 1
# 화면다시 그리기
screen.blit(section3, (0, section1_height))
# 플레이어 카드 변화
for i, item in enumerate(user_group):
if i == selected_card: # 선택된 카드에 대한 시각적 표시 (예: 선택된 카드를 약간 위로 올림)
item.update((50 + 50 * i, 470))
else:
item.update((50 + 50 * i, 500))
user_group.draw(screen)
pygame.display.update()
'''
# playerTurn 화면표시
font = pygame.font.SysFont('comicsansms', 20)
if playerTurn == 0:
text = font.render("Your turn", True, BLACK)
else:
text = font.render("{}'s turn".format(playerTurn), True, BLACK)
text_rect = text.get_rect(
center=(int(section3_width * 0.1), int(section3_height * 0.1)))
section3.blit(text, text_rect)
'''
# 섹션3 좌측 상단에 "Your turn" 텍스트 생성
font = pygame.font.SysFont('comicsansms', 20)
if playerTurn == 0:
text = font.render("Your turn", True, BLACK)
else:
text = font.render("{}'s turn".format(playerTurn), True, BLACK)
text_rect = text.get_rect(center=(int(section3_width * 0.1), int(section3_height * 0.1)))
# Draw a rectangle with white color as background
background_rect = pygame.Rect(text_rect.left - 10, text_rect.top - 10, text_rect.width + 20,
text_rect.height + 20) # create a larger rect for the background
pygame.draw.rect(section3, WHITE, background_rect) # draw the rect to the section3 surface
# Now draw the text
section3.blit(text, text_rect)
pygame.display.update()
pygame.display.update()
screen.blit(section1, (0, 0))
# 백 카드 스프라이트로 시도하기
backcard = Card('BACK', (screen_width, screen_height))
backcard.transform(160, 150)
backcard.update((int(section1_width * 0.20), int(section1_height * 0.45)))
backcard = pygame.sprite.RenderPlain(backcard)
backcard.draw(screen)
# top카드 이미지 변화
back = pygame.image.load('./최회민/img/{}.png'.format(discards[-1]))
back = pygame.transform.scale(back, (128, 162))
x = int(screen_width * 0.4)
y = int(screen_height * 0.4)
screen.blit(back, (300, 110, 10, 10))
# section1.blit(back, (300, 110, 10, 10))
pygame.display.update()
# 현재 색 표시 칸 구현
if curruntcolour == 'BLUE':
pygame.draw.circle(section1, BLUE,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'RED':
pygame.draw.circle(section1, RED,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'YELLOW':
pygame.draw.circle(section1, LIGHT_YELLOW,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'GREEN':
pygame.draw.circle(section1, GREEN,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
# Inside your game loop where you want to draw the text
print(len(card))
font = pygame.font.Font(None, 24)
card_count_text = str(len(card)) # convert the card count to string
text_surface = font.render(card_count_text, True, BLACK) # render the text
text_rect = text_surface.get_rect(
center=(
int(section1_width * 0.8), int(section1_height * 0.45))) # get the rect for positioning
section1.blit(text_surface, text_rect) # draw the text to the section1 surface
pygame.display.update()
pygame.display.update()
# 타이머 설정
time_limit = datetime.timedelta(minutes=2)
start_time = datetime.datetime.now()
end_time = start_time + time_limit
# 타이머 업데이트
current_time = datetime.datetime.now()
time_left = end_time - current_time
if time_left.total_seconds() <= 0:
text = bold_font.render("Time's up!", True, (255, 0, 0))
else:
seconds_left = int(time_left.total_seconds())
text = font.render(str(seconds_left), True, (0, 0, 0))
text_rect = text.get_rect(center=(timer_x + timer_width / 2, timer_y + timer_height / 2))
section3.blit(text, text_rect)
pygame.display.update()
# 사람인경우
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
elif event.key == custom_keys['left']: # 왼쪽 화살표 키가 눌렸을 때
selected_card = (selected_card - 1) % len(user_group)
# 화면다시 그리기
screen.blit(section3, (0, section1_height))
# 플레이어 카드 변화
for i, item in enumerate(user_group):
if i == selected_card: # 선택된 카드에 대한 시각적 표시 (예: 선택된 카드를 약간 위로 올림)
item.update((50 + 50 * i, 470))
else:
item.update((50 + 50 * i, 500))
user_group.draw(screen)
pygame.display.update()
elif event.key == custom_keys['right']: # 오른쪽 화살표 키가 눌렸을 때
selected_card = (selected_card + 1) % len(user_group)
# 화면다시 그리기
screen.blit(section3, (0, section1_height))
# 플레이어 카드 변화
for i, item in enumerate(user_group):
if i == selected_card: # 선택된 카드에 대한 시각적 표시 (예: 선택된 카드를 약간 위로 올림)
item.update((50 + 50 * i, 470))
else:
item.update((50 + 50 * i, 500))
user_group.draw(screen)
pygame.display.update()
elif event.key == custom_keys['return']: # enter 키가 눌렸을 때
if playerTurn == 0:
for i, sprite in enumerate(user_group):
if i == selected_card:
if check_card(curruntcolour, cardVal, sprite):
# 카드 낼때
discards.append(sprite.get_name())
user_group.remove(sprite) # 핸드에서 내려는 카드를 제거하고
players[playerTurn].remove(sprite.get_name())
if len(players[playerTurn]) == 0:
print("finish")
running = False
winner = playerTurn + 1
achiev.setStoryAWin()
if turn <= 10:
achiev.setIn10Turn()
text = font.render("YOU win! continue : enter", True, BLACK)
text_rect = text.get_rect(
center=(int(screen_width * 0.3), int(screen_height * 0.5)))
screen.blit(text, text_rect)
pygame.display.update()
# enter key 누르면 게임 종료
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == custom_keys['return']:
storymode2.story_map2()
# 버린카드 특별카드 체크
splitCard = discards[-1].split("_", 1)
curruntcolour = splitCard[0]
# 와일드면 카드값에 any부여
if curruntcolour == "BLACK":
cardVal = "Any"
else:
cardVal = splitCard[1]
# 와읻드면 색 선택하게
if curruntcolour == "BLACK":
curruntcolour = show_color_popup(screen, 500, 100, font, colors, color_values)
# 리버스면 다음턴 회전반대로
if cardVal == "REVERSE":
playDirection = playDirection * (-1)
if len(players) == 2:
playerTurn = change_turn(playDirection, numPlayers, playerTurn)
# 스킵하기
elif cardVal == "SKIP":
playerTurn = change_turn(playDirection, numPlayers, playerTurn)
# 2장 뽑기
elif splitCard[1] == "DRAW2":
playerDraw = next_draw(numPlayers, playDirection, playerTurn)
players[playerDraw].extend(drawCards(2))
# 컴퓨터 카드 변화구현
# 와일드 드로우 4
elif splitCard[1] == "DRAW4":
playerDraw = next_draw(numPlayers, playDirection, playerTurn)
players[playerDraw].extend(drawCards(4))
# 컴퓨터 카드 변화구현
# 색 체인지
elif splitCard[1] == "CHANGE":
curruntcolour = show_color_popup(screen, 500, 100, font, colors, color_values)
# 어게인
elif splitCard[1] == "AGAIN":
playDirection = playDirection * (-1)
playerTurn = change_turn(playDirection, numPlayers, playerTurn)
playDirection = playDirection * (-1)
# 턴 변화
playerTurn = change_turn(playDirection, numPlayers, playerTurn)
turn += 1
screen.blit(section1, (0, 0))
# 백 카드 스프라이트로 시도하기
backcard = Card('BACK', (screen_width, screen_height))
backcard.transform(160, 150)
backcard.update((int(section1_width * 0.20), int(section1_height * 0.45)))
backcard = pygame.sprite.RenderPlain(backcard)
backcard.draw(screen)
# top카드 이미지 변화
back = pygame.image.load('./최회민/img/{}.png'.format(discards[-1]))
back = pygame.transform.scale(back, (128, 162))
x = int(screen_width * 0.4)
y = int(screen_height * 0.4)
screen.blit(back, (300, 110, 10, 10))
# section1.blit(back, (300, 110, 10, 10))
pygame.display.update()
# 현재 색 표시 칸 구현
if curruntcolour == 'BLUE':
pygame.draw.circle(section1, BLUE,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'RED':
pygame.draw.circle(section1, RED,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'YELLOW':
pygame.draw.circle(section1, LIGHT_YELLOW,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
elif curruntcolour == 'GREEN':
pygame.draw.circle(section1, GREEN,
(int(section1_width * 0.8), int(section1_height * 0.45)),
int(section1_width * 0.05), 0)
# Inside your game loop where you want to draw the text
len(card)
font = pygame.font.Font(None, 24)
card_count_text = str(len(card)) # convert the card count to string
text_surface = font.render(card_count_text, True, BLACK) # render the text
text_rect = text_surface.get_rect(
center=(int(section1_width * 0.8),
int(section1_height * 0.45))) # get the rect for positioning
section1.blit(text_surface, text_rect) # draw the text to the section1 surface
pygame.display.update()
pygame.display.update()
# 화면다시 그리기
screen.blit(section3, (0, section1_height))
# 플레이어 카드 변화
for i, item in enumerate(user_group):
if i == selected_card: # 선택된 카드에 대한 시각적 표시 (예: 선택된 카드를 약간 위로 올림)
item.update((50 + 50 * i, 470))
else:
item.update((50 + 50 * i, 500))
user_group.draw(screen)
pygame.display.update()