import time,random
while True:
playernum = 0
emenynum = 0
for i in range(1,4):
time.sleep(2)
print('----现在是第%s局----' % i)
player_life = random.randint(100,150)
emeny_life = random.randint(100,150)
player_attack = random.randint(30,50)
emeny_attack = random.randint(30,50)
print('[玩家]\n血量:%s\n攻击:%s' % (player_life,emeny_attack))
time.sleep(1.5)
print('[电脑]\n血量:%s\n攻击:%s' % (emeny_life,emeny_attack))
time.sleep(1.5)
while player_life > 0 and emeny_life > 0:
player_life = player_life - emeny_attack
print('电脑发起攻击,玩家血量剩余%s' % player_life)
emeny_life = emeny_life - player_attack
print('玩家发起攻击,电脑血量剩余%s' % emeny_life)
print('-----------------')
time.sleep(1.5)
if player_life > 0 and emeny_life <= 0:
print('玩家获胜!')
playernum += 1
elif player_life <= 0 and emeny_life > 0:
print('电脑获胜!')
emenynum += 1
else:
print('平局!')
if playernum > emenynum:
print('玩家赢!')
elif playernum < emenynum:
print('电脑赢!')
else:
print('平局!')
again = input('是否想再次使用,输入q退出,输入其他继续:')
if again == 'q':
break
网友评论