-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_strawberry.py
More file actions
132 lines (115 loc) · 7.5 KB
/
game_strawberry.py
File metadata and controls
132 lines (115 loc) · 7.5 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
import time
import random
import re
def create_rhythm_sequences():
"""딸기 게임용 리듬 시퀀스를 생성합니다."""
rhythm_list = []
# 1~4번 패턴: 4박자 리듬
for seq_num in range(1, 5):
rhythm = ["X"] * 4
for idx in range(seq_num):
rhythm[3-idx] = "딸기"
rhythm_list.append(rhythm)
# 5~8번 패턴: 8박자 리듬
for seq_num in range(5, 9):
rhythm = ["X"] * 8
# 앞부분 4개는 모두 딸기
for idx in range(4):
rhythm[idx] = "딸기"
# 뒷부분에 추가 딸기 배치
for idx in range(seq_num - 4):
rhythm[7-idx] = "딸기"
rhythm_list.append(rhythm)
return rhythm_list
def display_rhythm_with_timing(sequence):
"""리듬을 타이밍에 맞춰 화면에 표시합니다."""
for item in sequence:
print(item, end=' ', flush=True)
time.sleep(0.3)
print()
def get_mountain_pattern_indices():
"""산 모양(1~8,7~1) 인덱스 시퀀스를 반환합니다."""
up = list(range(8))
down = list(range(6, 0, -1))
return up + down
def clean_input(s):
"""입력값에서 공백, 대소문자, 특수문자를 모두 제거합니다."""
return re.sub(r'[^\w가-힣]', '', s).lower()
def execute_strawberry_game(player_data, main_player):
"""딸기 게임 메인 실행 함수"""
print(r'''
,----, ,---, ,---,
,/ .`| ____ ,`--.' | ,`--.' |
.--.--. ,` .' :,-.----. ,---, .---. ,---,. ,---,.,-.----. ,-.----. ,----.. ,---, ,' , `. ,---,. | : : | : :
/ / '. ; ; /\ / \ ' .' \ /. ./| ,' .' \ ,' .' |\ / \ \ / \ ,---, / / \ ' .' \ ,-+-,.' _ | ,' .' | ' ' ; ' ' ;
| : /`. /.'___,/ ,' ; : \ / ; '. .--'. ' ;,---.' .' |,---.' |; : \ ; : \ /_ ./| | : : / ; '. ,-+-. ; , ||,---.' | | | | | | |
; | |--` | : | | | .\ : : : \ /__./ \ : || | |: || | .'| | .\ : | | .\ :,---, | ' : . | ;. / : : \ ,--.'|' | ;|| | .' ' : ; ' : ;
| : ;_ ; |.'; ; . : |: | : | /\ \ .--'. ' \' .: : : /: : |-,. : |: | . : |: /___/ \. : | . ; /--` : | /\ \ | | ,', | ':: : |-, | | ' | | '
\ \ `.`----' | | | | \ : | : ' ;. : /___/ \ | ' ': | ; : | ;/|| | \ : | | \ :. \ \ ,' ' ; | ; __ | : ' ;. : | | / | | ||: | ;/| ' : | ' : |
`----. \ ' : ; | : . / | | ;/ \ \; \ \; :| : \| : .'| : . / | : . / \ ; ` ,' | : |.' .'| | ;/ \ \' | : | : |,| : .' ; | ; ; | ;
__ \ \ | | | ' ; | | \ ' : | \ \ ,' \ ; ` || | . || | |-,; | | \ ; | | \ \ \ ' . | '_.' :' : | \ \ ,'; . | ; |--' | | |-, `---'. | `---'. |
/ /`--' / ' : | | | ;\ \| | ' '--' . \ .\ ;' : '; |' : ;/|| | ;\ \| | ;\ \ ' \ | ' ; : \ || | ' '--' | : | | , ' : ;/| `--..`; `--..`;
'--'. / ; |.' : ' | \. '| : : \ \ ' \ || | | ; | | \: ' | \.': ' | \' \ ; ; ' | '/ .'| : : | : ' |/ | | \ .--,_ .--,_
`--'---' '---' : : :-' | | ,' : ' |--" | : / | : .': : :-' : : :-' : \ \ | : / | | ,' ; | |`-' | : .' | |`. | |`.
| |.' `--'' \ \ ; | | ,' | | ,' | |.' | |.' \ ' ; \ \ .' `--'' | ;/ | | ,' `-- -`, ;`-- -`, ;
`---' '---" `----' `----' `---' `---' `--` `---` '---' `----' '---`" '---`"
''')
print("\n=== 🍓 딸기 게임 시작! ===")
print("딸기가 좋아~ 딸기가 좋아~ 딸기! 딸기! 딸기!딸기!딸기\n")
rhythm_sequences = create_rhythm_sequences()
mountain_indices = get_mountain_pattern_indices()
current_round = 0
turn_index = 0
player_count = len(player_data)
mountain_length = len(mountain_indices)
while True:
# 산 모양 인덱스 사용
pattern_idx = mountain_indices[current_round % mountain_length]
active_player = player_data[turn_index % player_count]
current_rhythm = rhythm_sequences[pattern_idx]
correct_answer = ''.join(current_rhythm)
# 안내 메시지
print(f" {active_player['name']}님의 차례!")
print("입력 예시: x x x 딸기 (띄어쓰기, 대소문자, 특수문자 상관없이 입력하세요!)")
# 플레이어 입력 처리
if active_player['name'] == main_player:
player_input = input("> ")
else:
# AI 플레이어 행동 결정 (90% 정답률)
ai_success_rate = random.random()
if ai_success_rate < 0.9:
player_input = correct_answer
print(f"{active_player['name']}님 차례: {player_input}")
else:
# AI가 실수하는 경우
wrong_answer = list(correct_answer)
if "딸기" in wrong_answer:
mistake_pos = wrong_answer.index("딸기")
wrong_answer[mistake_pos] = "x"
else:
wrong_answer[0] = "딸기"
player_input = ''.join(wrong_answer)
print(f"{active_player['name']}님 차례: {player_input}")
time.sleep(1)
# 입력값 정제 후 비교
cleaned_input = clean_input(player_input)
cleaned_answer = clean_input(correct_answer)
# 정답 체크
if cleaned_input != cleaned_answer:
print(f"❌ 틀렸습니다!\n입력값: {player_input}\n정답: {correct_answer}")
print("정답 리듬: ", end=""); display_rhythm_with_timing(current_rhythm)
print(f"{active_player['name']} 님은 하나 더 마신다!")
# 게임 재시작 여부 확인
restart_choice = input("딸기 게임을 처음부터 다시 할까요? (y/n): ").strip().lower()
if restart_choice == "y":
print("\n게임을 처음부터 다시 시작합니다!\n")
current_round = 0
turn_index = (turn_index + 1) % player_count # 틀린 다음 사람부터 시작
continue
else:
print("🍺 딸기 게임 종료!")
return active_player['name']
else:
print(f"정답! 🎉\n")
current_round += 1
turn_index += 1