-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
217 lines (167 loc) · 6.62 KB
/
Copy pathmain.py
File metadata and controls
217 lines (167 loc) · 6.62 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
# Piro25_PythonGame_2/main.py
from games import game_1, game_2, game_3, game_4, game_5
from players import Player, find_player
import random
game_list = {
1: ('홍삼게임', game_1),
2: ('딸기당근수박참외메론게임', game_2),
3: ('어목조동게임', game_3),
4: ('숫자게임', game_4),
5: ('지하철게임', game_5),
}
name_list = ['보민', '현민', '주헌', '지연', '희원']
# 사용자 이름 받기
def get_player_name():
while True:
name = input("오늘 거하게 취해볼 당신의 이름은 ? : ").strip()
if name:
return name
print("이름을 입력해주세요 : ")
# 주량 선택하기
def get_player_capacity():
options = {
1: 2,
2: 4,
3: 6,
4: 8,
5: 10,
}
print('소주 기준 당신의 주량은 ?')
print('1. 소주 반 병 (2잔)')
print('2. 소주 반 병에서 한 병 (4잔)')
print('3. 소주 한 병에서 한 병 반 (6잔)')
print('4. 소주 한 병 반에서 두 병 (8잔)')
print('5. 소주 두 병 이상 (10잔)')
while True:
choice = input('당신의 치사량(주량)은 얼마만큼인가요 ? (1~5를 선택해주세요) : ')
if choice.isdigit() and int(choice) in options: # choice가 숫자인지, 1~5 범위인지 체크
return options[int(choice)]
else:
print('1~5 사이의 숫자를 입력해주세요 : ')
# 대결할 사람 초대하기 (최대 3명)
def invite():
friends = []
while True:
count = input('함께 취할 친구들은 얼마나 필요하신가요 ? (최대 3명까지 초대할 수 있어요 !) : ')
if count.isdigit() and 1 <= int(count) <= 3: # count가 숫자인지, 1~3 범위인지 체크
count = int(count)
break
else:
print('1~3 사이의 숫자를 입력해주세요 : ')
friend_names = random.sample(name_list, count)
for friend_name in friend_names:
capacity = random.choice([2, 4, 6, 8, 10])
friend = Player(friend_name, capacity)
print(f'오늘 함께 취할 친구는 {friend_name}입니다! (치사량 : {capacity})')
friends.append(friend)
return friends
# 현재 상황 출력하기
def print_status(players):
print("\n" + "~" * 40)
print(" 현재 플레이어들의 음주 상태 ")
print("-" * 40)
for p in players:
print(f"{p.name}은(는) 지금까지 {p.drunk}잔 | 치사량까지 {p.remaining()}잔")
print("~" * 40 + "\n")
# 게임 리스트 출력하기
def print_game_list():
print("~" * 20)
print("오늘의 Alcohol GAME")
print("~" * 20)
for num, game_info in game_list.items():
print(f"{num}. {game_info[0]}")
print("~" * 40)
# 게임 번호 선택 받고, 리턴 받은 결과 players에 반영
def play_one_round(current_player, players):
is_human = (current_player == players[0])
# 게임 선택 목록 출력
print_game_list()
choice = None
if is_human:
# 내 차례일 때: 직접 입력 받기
print(f"이번 라운드는 {current_player.name}의 턴입니다! 게임을 선택해 주세요.")
while True:
user_input = input("원하는 게임의 번호를 선택하세요 (1~5): ")
if user_input.strip().lower() == 'exit':
print("\n게임을 종료합니다.")
exit()
if user_input.isdigit() and int(user_input) in game_list:
choice = int(user_input)
break
print("올바른 게임 번호를 선택해 주세요.")
else:
# 컴퓨터 차례일 때: 랜덤
print(f"술게임 진행중! 다른 사람의 턴입니다. 그만하고 싶으면 \"exit\"를, 계속하고 싶으면 아무키나 입력해 주세요! : ")
user_action = input()
if user_action.strip().lower() == 'exit':
print("\n 게임을 종료합니다.")
exit()
# 컴퓨터가 1~5 중 하나를 랜덤으로 선택
choice = random.choice(list(game_list.keys()))
print("~" * 65)
print(f"{current_player.name}(이)가 좋아하는 랜덤 게임~ 랜덤 게임~ 무슨 게임? : {choice}")
print("~" * 65)
# 선택된 게임
game_name, game_module = game_list[choice]
print(f"\n{current_player.name} 님이 게임을 선택하셨습니다! \n")
current_player_name = current_player.name
other_names = [
player.name
for player in players
if player != current_player
]
user_name = players[0].name
game_result = game_module.play(
current_player_name,
other_names,
user_name,
)
# 결과 반영 및 정산
if not game_result:
print("\n아무도 걸리지 않았습니다. 다음 라운드로 이동합니다.")
return
print("\n 벌칙자 발생")
for key, drink_count in game_result.items():
if isinstance(key, str):
search_name = key.strip()
else:
search_name = key.name.strip()
loser = find_player(players, search_name)
if loser:
loser.add_drink(drink_count)
print(f"{loser.name}님이 {drink_count}잔을 마십니다! (현재 총 {loser.drunk}잔 마심)")
# main 함수
def main():
print("안주 먹을 시간이 없어요 마시면서 배우는 술게임\n")
# 1. 내 정보 입력 받기
my_name = get_player_name()
my_capacity = get_player_capacity()
me = Player(my_name, my_capacity)
# 2. 친구들 초대하기
players = [me] + invite()
# 게임 루프 시작
round_count = 1
while True:
print(f"\n[ROUND {round_count}] 게임을 시작합니다.")
print_status(players)
current_player = players[(round_count - 1) % len(players)]
play_one_round(current_player, players)
# 3. 치사량 도달 체크
dead_players = []
for p in players:
if p.is_dead():
dead_players.append(p)
if dead_players:
print_status(players)
for p in dead_players:
print(
f"\n{p.name}이(가) 전사했습니다... "
"꿈나라에서는 편히 쉬시길..ZZZ"
)
print("~" * 65)
print("\n다음에 술마시면 또 불러주세요~ 안녕!\n")
print("~" * 65)
break
round_count += 1
if __name__ == "__main__":
main()