import random
print("*"*10+"唐僧大战白骨精"+"*"*10)
name = input('请选择你的身份:\n\t1.唐僧\n\t2.白骨精\n请选择:')
if name == '2':
print("咦你竟然选择白骨精,就不让你是白骨精")
elif name == '1':
print("恭喜你选择的是唐僧")
else:
print('操作错误,罚你是唐僧')
xie = 2
gong = 2
fang = 2
bai_xie = 20
bai_gong = 20
bai_fang = 20
print("——"*25)
print(f'你现在的身份是唐僧,生命值{xie},攻击力{gong},防御力{fang}')
print('游戏开始')
flag = True
while flag:
print(f'唐僧的状态,生命值{xie},攻击力{gong},防御力{fang}')
xuan = input('请选择你的操作\n1.刷怪,\n2.打白骨精,\n3.退出游戏\n请选择: ')
if xuan == '1':
xie += random.randint(-1,5)
if gong < 20 and fang <20 :
gong += random.randint(0, 4)
fang += random.randint(0, 4)
gong += random.randint(0,2)
fang += random.randint(0,2)
if xie <= 0:
print('你被小怪打死了,游戏结束')
break
print('恭喜您升级了')
elif xuan == '2':
print('boos大战即将开始')
while flag:
print('请选择你的操作:\n1.普通攻击\n2.全力一击\n3.防御\n4.逃跑')
play = input()
if play == '1':
if 0 > (gong - bai_fang * 0.8):
print('白骨精的防御力太高,攻击没有掉血')
else:
print(f'唐僧攻击成功:白骨精失去{gong - bai_fang * 0.8}血量')
bai_xie -= gong-bai_fang*0.8
if bai_gong - fang*0.8 < 0:
print('唐僧的防御力太高,攻击没有掉血')
else:
print(f"白骨精攻击奏效,唐僧失去{bai_gong - fang*0.8}")
xie -= bai_gong - fang*0.8
elif play == '2':
print(f'全力一击失去{xie*0.3}血量')
xie -= xie*0.3 # 减去总血量的百分之三十
if 0 > (gong - bai_fang * 0.4):
print('白骨精的防御力太高,攻击没有掉血')
else:
print(f'唐僧攻击成功:白骨精失去{gong - bai_fang * 0.5}血量')
bai_xie -= gong-bai_fang*0.5
if bai_gong - fang*0.6 < 0: # 防御降低0.2
print('唐僧的防御力太高,攻击没有掉血')
else:
print(f"白骨精攻击成功,唐僧失去{bai_gong - fang*0.6}")
xie -= bai_gong - fang*0.6
elif play == '3':
if bai_gong - fang< 0:
print('唐僧的防御力太高,攻击没有掉血')
else:
print(f"白骨精攻击成功,唐僧失去{bai_gong - fang }")
xie -= bai_gong - fang
elif play == '4':
print('逃跑成功')
break
else:
print('操作错误,请重新输入')
continue
if bai_xie <= 0:
print('恭喜你战胜了白骨精')
flag = False
elif xie <= 0:
print('唐僧失败了,游戏结束')
flag = False
elif xuan == '3':
flag = False
else:
print('输入有误,请重新操作')