依靠现学有限的知识写的数字炸弹
数字炸弹规则:系统在指定范围内随机生成一个数字,每名玩家依次猜选,若猜中,炸弹爆炸,该玩家被淘汰;若未猜中则进一步缩小范围。

源码:

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
#!/usr/bin/python3

print("欢迎来到“数字炸弹”!")
print("******************************")

select1 = 0

while select1 != 3:

select1 = int(input("请选择操作(1.开始游戏/2.游戏说明/3.退出):"))
print("******************************")


if select1 == 1:

select2 = int(input("设置游戏难度(1.简单模式/2.困难模式/3.地狱模式/4.自定义模式/5.单人模式):"))
print("******************************")

# 简单模式

if select2 == 1:
print("简单模式(范围1~100)")
print("******************************")
import random
boom = random.choice(range(101))
players = int(input("请输入玩家个数:"))
print("******************************")
print("游戏开始")
print("******************************")
n = 1
guess = 0
maxnum = 101
minnum = 0
while guess != boom:
guess = int(input("请玩家 %d 输入:"%(n)))
if guess <= minnum or guess >= maxnum :
print("警告:范围在", minnum, "~", maxnum, "以内!")
elif guess == boom:
print("BOOM!!!玩家 %d 出局,游戏结束"%(n))
print("******************************")
elif guess < boom:
minnum = guess
print("猜小了(范围缩小到", minnum, "~", maxnum, "以内)")
if n < players:
n = n+1
else:
n = 1
elif guess > boom:
maxnum = guess
print("猜大了(范围缩小到", minnum, "~", maxnum, "以内)")
if n < players:
n = n+1
else:
n = 1
# 困难模式

if select2 == 2:
print("困难模式(范围1~50)")
print("******************************")
import random
boom = random.choice(range(51))
players = int(input("请输入玩家个数:"))
print("******************************")
print("游戏开始")
print("******************************")
n = 1
guess = 0
maxnum = 51
minnum = 0
while guess != boom:
guess = int(input("请玩家 %d 输入:"%(n)))
if guess <= minnum or guess >= maxnum :
print("警告:范围在", minnum, "~", maxnum, "以内!")
elif guess == boom:
print("BOOM!!!玩家 %d 出局,游戏结束"%(n))
print("******************************")
elif guess < boom:
minnum = guess
print("猜小了(范围缩小到", minnum, "~", maxnum, "以内)")
if n < players:
n = n+1
else:
n = 1
elif guess > boom:
maxnum = guess
print("猜大了(范围缩小到", minnum, "~", maxnum, "以内)")
if n < players:
n = n+1
else:
n = 1

# 地狱模式
if select2 == 3:
print("地狱模式(范围1~30)")
print("******************************")
import random
boom = random.choice(range(31))
players = int(input("请输入玩家个数:"))
print("******************************")
print("游戏开始")
print("******************************")
n = 1
guess = 0
maxnum = 31
minnum = 0
while guess != boom:
guess = int(input("请玩家 %d 输入:"%(n)))
if guess <= minnum or guess >= maxnum :
print("警告:范围在", minnum, "~", maxnum, "以内!")
elif guess == boom:
print("BOOM!!!玩家 %d 出局,游戏结束"%(n))
print("******************************")
elif guess < boom:
minnum = guess
print("猜小了(范围缩小到", minnum, "~", maxnum, "以内)")
if n < players:
n = n+1
else:
n = 1
elif guess > boom:
maxnum = guess
print("猜大了(范围缩小到", minnum, "~", maxnum, "以内)")
if n < players:
n = n+1
else:
n = 1

# 自定义模式

if select2 == 4:
print("自定义模式(一个炸弹,目前只支持自定义炸弹范围)")
print("******************************")
boomrange = int(input("设置炸弹范围:"))
print("******************************")
import random
boom = random.choice(range(boomrange + 1))
players = int(input("请输入玩家个数:"))
print("******************************")
print("游戏开始")
print("******************************")
n = 1
guess = 0
maxnum = boomrange + 1
minnum = 0
while guess != boom:
guess = int(input("请玩家 %d 输入:"%(n)))
if guess <= minnum or guess >= maxnum :
print("警告:范围在", minnum, "~", maxnum, "以内!")
elif guess == boom:
print("BOOM!!!玩家 %d 出局,游戏结束"%(n))
print("******************************")
elif guess < boom:
minnum = guess
print("猜小了(范围缩小到", minnum, "~", maxnum, "以内)")
if n < players:
n = n+1
else:
n = 1
elif guess > boom:
maxnum = guess
print("猜大了(范围缩小到", minnum, "~", maxnum, "以内)")
if n < players:
n = n+1
else:
n = 1

# 单人模式
if select2 == 5:
print("单人模式")
print("******************************")
boomrange = int(input("设置炸弹范围:"))
import random
boom = random.choice(range(boomrange + 1))
print("******************************")
guess = 0
maxnum = boomrange + 1
minnum = 0
while guess != boom:
guess = int(input("请玩家输入:"))
if maxnum - minnum == 2:
print("玩家胜利!!!游戏结束")
print("******************************")
elif guess <= minnum or guess >= maxnum :
print("警告:范围在", minnum, "~", maxnum, "以内!")
elif guess == boom:
print("BOOM!!!游戏结束")
print("******************************")
elif guess < boom:
minnum = guess
print("猜小了(范围缩小到", minnum, "~", maxnum, "以内)")
elif guess > boom:
maxnum = guess
print("猜大了(范围缩小到", minnum, "~", maxnum, "以内)")

elif select1 == 2:
print("系统在指定范围内随机生成一个数字,每名玩家依次猜选,若猜中,炸弹爆炸,该玩家被淘汰;若未猜中则进一步缩小范围")
print("******************************")

elif select1 == 3:
print("下次再见!")
print("******************************")