python入门pk小游戏

import time
import random flag = True
while flag:
player_win = 0
enemy_win = 0
for i in range(1, 4):
print('第'+str(i)+'轮pk赛')
player_life = random.randint(100, 150)
enemy_life = random.randint(100, 150)
player_attack = random.randint(20, 30)
enemy_attack = random.randint(20, 30)
print("【自己】\n生命值:{}\n攻击值:{}".format(player_life, player_attack))
print('-----------------------')
time.sleep(1)
print("【敌人】\n生命值:{}\n攻击值:{}".format(enemy_life, enemy_attack))
print('-----------------------')
time.sleep(1) while player_life > 0 and enemy_life > 0:
enemy_life = enemy_life-player_attack
print("您向敌人发起了攻击,敌人的生命值剩余:{}".format(enemy_life))
time.sleep(1)
player_life = player_life-enemy_attack
print("敌人向您发起了反击,您的生命值剩余:{}".format(player_life))
print('-----------------------')
time.sleep(1) if (player_life > 0) and (enemy_life <= 0):
player_win += 1
print('您赢了')
elif (player_life <= 0) and (enemy_life > 0):
enemy_win += 1
print('敌人赢了')
elif (enemy_life < 0) and (player_life < 0):
print('平局') print('-----------------------')
time.sleep(1)
if player_win > enemy_win:
print('您赢了')
elif enemy_win > player_win:
print('敌人赢了')
else:
print('平局') ask = input('你要再来一局吗?继续输入y,其他退出')
if ask == 'y':
flag = True
else:
flag = False
print('已结束')

  

上一篇:linux环境中 对tomcat配置java环境


下一篇:40个Python入门小程序