Commit d8be51d6 by BellCodeEditor

save project

parent 77955b83
Showing with 23 additions and 9 deletions
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' # 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
with open(r'C:\Users\CM\Desktop\book.txt','a',encoding= 'utf-8') as file1 class Hreo:
for data in file1: def_init_(self,name):
if '小强:10本\n' in data: self.level =1
print('小强数据在文件中') self.hp = 250
if '小兰:12本\n' in data: self.attack = 40
print('小兰数据在文件中') self.name = name
def combat(self,enemy):
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"血量"
enemy.hp-=self.attack
if enemy.hp>0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3
print(info)
else:
info3 = enemy.name+"死亡,游戏结束"
info = info1+info2+info3
print(info)
exit()
yase = Hreo("垭瑟")
houyi=Hreo("后羿")
yase.combat(houyi)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment