马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 小伤口 于 2020-12-26 17:32 编辑
交第38讲作业啦
这是写的小游戏,写完之后才发现代码可以缩写好多的。但已经1点多了不想改了
希望不会有bug
话不多说放代码
第一次发作品好羞涩import random as r
def gongjili(x):
x=x+int(c)
if x>100:
x=100
return x
def nengliang(x):
x=x+int(e)
if x>150:
x=150
return x
def shengmingzhi(x):
x=x+int(d)
if x>800:
x=800
return x
def fangyujia(x):
x=x+int(s)
if x>150:
x=150
return x
def gongjili1(x):
x=x+r.randint(10,40)
if x>100:
x=100
return x
def nengliang1(x):
x=x+r.randint(10,40)
if x>150:
x=150
return x
def shengmingzhi1(x):
x=x+r.randint(10,40)
if x>800:
x=800
return x
def fangyujia1(x):
x=x+r.randint(10,40)
if x>150:
x=150
return x
juhuaguai={'攻击力':50,'生命值':800,'能量':100,'防御甲':150}
taohuaxia={'攻击力':50,'生命值':800,'能量':150,'防御甲':100}
print('游戏说明:每局你都会有80个元晶,可以加任何属性包括生命值,转换率都是1:1.生命值为0游戏就结束')
print('')
print('能量和防御甲每局都会损耗,但是数值越高攻击力造成的伤害或防御能力也会相应的提高')
print('')
print('选1为菊花怪 世人甚爱牡丹,吾独爱菊---菊花怪 ',juhuaguai)
print('')
print('选2为桃花侠 只为桃花不为侠---桃花侠',taohuaxia)
temp=input('请选择人物')
a=80
f=80
while 1:
if juhuaguai['生命值']<=0:
print('菊花怪被打败了')
break
if taohuaxia['生命值'] <=0:
print('桃花侠被打败了')
break
if temp!='1' and temp!='2':
print('请正确输入')
break
if juhuaguai['生命值']>0 and taohuaxia['生命值']>0:
print('战斗打响了')
if taohuaxia['能量']>0 and juhuaguai['防御甲']>0:
juhuaguai['生命值']=juhuaguai['生命值']-taohuaxia['攻击力']*taohuaxia['能量']*0.01+juhuaguai['防御甲']*0.38
if taohuaxia['能量']>0 and juhuaguai['防御甲']<=0:
juhuaguai['生命值']=juhuaguai['生命值']-taohuaxia['攻击力']*taohuaxia['能量']*0.01
if taohuaxia['能量']<=0 and juhuaguai['防御甲']>0:
juhuaguai['生命值']=juhuaguai['生命值']-taohuaxia['攻击力']*0.5+juhuaguai['防御甲']*0.38
if taohuaxia['能量']<=0 and juhuaguai['防御甲']<=0:
juhuaguai['生命值']=juhuaguai['生命值']-taohuaxia['攻击力']*0.5
if juhuaguai['能量']<=0 and taohuaxia['防御甲']<=0 :
taohuaxia['生命值']=taohuaxia['生命值']-juhuaguai['攻击力']*0.5
if juhuaguai['能量']<=0 and taohuaxia['防御甲']>0:
taohuaxia['生命值']=taohuaxia['生命值']-juhuaguai['攻击力']*0.5+taohuaxia['防御甲']*0.38
if juhuaguai['能量']>0 and taohuaxia['防御甲']>0:
taohuaxia['生命值']=taohuaxia['生命值']-juhuaguai['攻击力']*juhuaguai['能量']*0.01+taohuaxia['防御甲']*0.38
if juhuaguai['能量']>0 and taohuaxia['防御甲']<=0:
taohuaxia['生命值']=taohuaxia['生命值']-juhuaguai['攻击力']*juhuaguai['能量']*0.01
juhuaguai['能量']=juhuaguai['能量']-r.randint(15,27)
juhuaguai['防御甲']=juhuaguai['防御甲']-r.randint(15,27)
if juhuaguai['能量']<=0:
juhuaguai['能量']=0
taohuaxia['能量']=taohuaxia['能量']-r.randint(15,27)
taohuaxia['防御甲']=taohuaxia['防御甲']-r.randint(15,27)
if taohuaxia['能量']<=0:
taohuaxia['能量']=0
if juhuaguai['防御甲']<=0:
juhuaguai['防御甲']=0
if taohuaxia['防御甲']<=0:
taohuaxia['防御甲']=0
print('菊花怪现在攻击力为:',juhuaguai['攻击力'])
print('菊花怪现在生命值为:',juhuaguai['生命值'])
print('菊花怪现在能量为:',juhuaguai['能量'])
print('菊花怪现在防御甲为:', juhuaguai['防御甲'])
print(' ')
print('桃花侠现在攻击力为:',taohuaxia['攻击力'])
print('桃花侠现在生命值为:',taohuaxia['生命值'])
print('桃花侠现在能量为:',taohuaxia['能量'])
print('桃花侠现在防御甲为:',taohuaxia['防御甲'])
if juhuaguai['生命值']<=0:
print('菊花怪被打败了')
break
if taohuaxia['生命值'] <=0:
print('桃花侠被打败了')
break
if temp=='1':
print('')
print('按1进入转化攻击力渠道')
print('按2进入转化生命值渠道')
print('按3进入转化能量渠道')
print('按4进入转化防御甲通道')
while 1:
if not a:
break
b=input('请选择元晶转化渠道:')
if b=='1':
c=input('请分配你的元晶(攻击力上限为100):')
if int(c)<=a:
juhuaguai['攻击力']=gongjili(juhuaguai['攻击力'])
print('攻击力现在为:',juhuaguai['攻击力'])
a=a-int(c)
print('元晶还剩:',a)
else:
print('元晶不够啦')
if b=='2':
d=input('请分配你的元晶(生命值上限为800):')
if int(d)<=a:
juhuaguai['生命值']=shengmingzhi(juhuaguai['生命值'])
print('生命值现在为:',juhuaguai['生命值'])
a=a-int(d)
print('元晶还剩:',a)
else:
print('元晶不够啦')
if b=='3':
e=input('请分配你的元晶(能量上限为150):')
if int(e)<=a:
juhuaguai['能量']=nengliang(juhuaguai['能量'])
print('能量现在为:',juhuaguai['能量'])
a=a-int(e)
print('元晶还剩:',a)
else:
print('元晶不够啦')
if b=='4':
s=input('请分配你的元晶(防御值上限为150):')
if int(s)<=a:
juhuaguai['防御甲']=fangyujia(juhuaguai['防御甲'])
a=a-int(s)
print('元晶还剩:',a)
else:
print('元晶不够啦')
taohuaxia['能量']=nengliang1(taohuaxia['能量'])
taohuaxia['攻击力']=gongjili1(taohuaxia['攻击力'])
taohuaxia['生命值']=shengmingzhi1(taohuaxia['生命值'])
taohuaxia['防御甲']=fangyujia1(taohuaxia['防御甲'])
a+=80
if temp=='2':
print('')
print('按1进入转化攻击力渠道')
print('按2进入转化生命值渠道')
print('按3进入转化能量渠道')
print('按4进入转化防御甲通道')
while 1:
if not f:
break
g=int(input('请输入元晶转化渠道:'))
if g==1:
c=int(input('请分配你的元晶(攻击力上限为100)'))
if c<=f:
taohuaxia['攻击力']=gongjili(taohuaxia['攻击力'])
print('攻击力现在为:',taohuaxia['攻击力'])
f=f-int(c)
print('元晶还剩:',f)
else:
print('元晶不够啦')
if g==2:
d=int(input('请分配你的元晶(生命值上限为800):'))
if d<=f:
taohuaxia['生命值']=shengmingzhi(taohuaxia['生命值'])
print('生命值现在为:',taohuaxia['生命值'])
f=f-int(d)
print('元晶还剩:',f)
else:
print('元晶不够啦')
if g==3:
e=int(input('请分配你的元晶(能量上限为150):'))
if e<=f:
taohuaxia['能量']=nengliang(taohuaxia['能量'])
print('能量现在为:',taohuaxia['能量'])
f=f-int(e)
print('元晶还剩:',f)
else:
print('元晶不够啦')
if g==4:
s=int(input('请分配你的元晶(防御值上限为150):'))
if s<=f:
taohuaxia['防御甲']=fangyujia(taohuaxia['防御甲'])
print('防御甲现在为:',taohuaxia['防御甲'])
f=f-s
print('元晶还剩:',f)
else:
print('元晶不够啦')
f+=80
juhuaguai['攻击力']=gongjili1(juhuaguai['攻击力'])
juhuaguai['生命值']=shengmingzhi1(juhuaguai['生命值'])
juhuaguai['能量']=nengliang1(juhuaguai['能量'])
juhuaguai['防御甲']=fangyujia1(juhuaguai['防御甲'])
|