Python写的数字炸弹游戏，有简单和困难两个难度。

import random import time player = 0 computer = 0 print('[数字炸弹游戏]') print('''
——————————————————————————————————————————————— [游戏规则：1-100的炸弹编号中，其中一个编号是引爆编号。

——————————————————————————————————————————————— ''') while True: print()
print(f'[开始游戏][玩家得分：{player}][电脑得分：{computer}]') D = int(input('[请选择难度][1.普通
2.困难]：')) if D == 1: print('[当前难度][普通]') bomb = random.randint(1, 100) a = 0 b
= 100 while True: print('-'*30) N = int(input('[玩家][请输入一个炸弹编号]：')) if N <= a or
N >= b: print('[编号输入范围错误]') continue else: time.sleep(0.5) if N != bomb: if a <
N < bomb: a = N print(f'当前可输入的范围：[{a}]-[{b}]') elif bomb < N < b: b = N
print(f'当前可输入的范围：[{a}]-[{b}]') else: print('[BOOOOM!!]')
print('[你引爆了炸弹][电脑获胜]') computer += 1 break time.sleep(1) print('-'*30) M =
random.randint(a+1, b-1) print(f'[电脑][输入了一个炸弹编号]：{M}') time.sleep(0.5) if M !=
bomb: if a < M < bomb: a = M print(f'当前可输入的范围：[{a}]-[{b}]') elif bomb < M < b:
b = M print(f'当前可输入的范围：[{a}]-[{b}]') else: print('[BOOOOM!!]')
print('[电脑引爆了炸弹][玩家获胜]') player += 1 break else: print('[当前难度][困难]') bomb =
random.randint(1, 100) a = 0 b = 100 while True: print('-' * 30) N =
int(input('[玩家][请输入一个炸弹编号]：')) if N <= a or N >= b: print('[编号输入范围错误]')
continue else: time.sleep(0.5) if N != bomb: if a < N < bomb: a = N
print(f'当前可输入的范围：[{a}]-[{b}]') elif bomb < N < b: b = N
print(f'当前可输入的范围：[{a}]-[{b}]') else: print('[BOOOOM!!]')
print('[你引爆了炸弹][电脑获胜]') computer += 1 break time.sleep(1) print('-' * 30) M =
random.randint(a + 1, b - 1) if M == bomb: M = random.randint(a + 1, b - 1)
print(f'[电脑][输入了一个炸弹编号]：{M}') time.sleep(0.5) if M != bomb: if a < M < bomb: a
= M print(f'当前可输入的范围：[{a}]-[{b}]') elif bomb < M < b: b = M
print(f'当前可输入的范围：[{a}]-[{b}]') else: print('[BOOOOM!!]')
print('[电脑引爆了炸弹][玩家获胜]') player += 1 break

GitHub

Gitee