-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_tofu.py
More file actions
81 lines (71 loc) · 2.86 KB
/
game_tofu.py
File metadata and controls
81 lines (71 loc) · 2.86 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
import time
import random
def tofuGame(players_list, start_name):
# players_list: list of dicts with keys 'name', 'limit', 'drinks'
names = [player['name'] for player in players_list]
total = len(names)
# 안내 멘트
print(f"{' '.join(names)} 순으로 시계방향으로 앉아주세요.")
time.sleep(1.0)
print("두부는 본인 기준으로 오른쪽으로 갈수록 증가합니다!")
time.sleep(1.0)
print("두부두부두부 으쌰으쌰으쌰으쌰 두~부두부두부 으쌰으쌰으쌰으쌰")
# 시작 멤버를 지정된 사람으로 설정
if start_name in names:
current = names.index(start_name)
else:
current = 0
print(f"시작은 {names[current]}!")
# 첫 두부 입력
while True:
try:
tofu = int(input('두부 몇 모? '))
if 1 <= tofu <= 5:
break
print('1~5 사이의 숫자를 입력하세요.')
except ValueError:
print('숫자로 입력해주세요')
# 게임 루프
while True:
if tofu == 1:
current = (current + 2) % total
elif tofu == 2:
current = (current + 1) % total
elif tofu == 3:
print('두부는 네모! 두부는 네모! 네모! 네모! 네모네모네모!!')
return names[current]
elif tofu == 4:
current = (current - 1) % total
else:
current = (current - 2) % total
if names[current] != start_name:
tofu = random.randint(1, 5)
time.sleep(2.0)
print(">> (입력 예시: 홍길동 4)", names[current], tofu)
if tofu == 3:
print("두부는 네모! 두부는 네모! 네모! 네모! 네모네모네모!!")
return names[current]
else:
while True:
# 다음 입력: 플레이어 이름과 두부 수
startTime = time.time()
entry = input('>> (입력 예시: 홍길동 4) ').split()
endTime = time.time()
elapsed = endTime - startTime
# 예외 처리
try:
if len(entry) != 2:
print('형식에 맞게 입력해주세요: (이름) (숫자)')
continue
elif int(entry[1]) < 1 or int(entry[1]) > 5:
print('1~5 사이의 숫자를 입력해주세요.')
continue
except ValueError:
print('두 번째 입력은 숫자여야 해요!')
continue
if elapsed > 5:
print('너무 늦게 말했습니다!')
return names[current]
else:
tofu = int(entry[1])
break