Commit f0e4c539 by BellCodeEditor

auto save

parent dfb5d1b6
Showing with 37 additions and 0 deletions
import random
class Hero(object):
def __init__(self, name,hp):
self.level = 1
self.hp = hp
self.attack = 40
self.name = name
def combat(self,enemy):
x = random.randint(1,10)
if x >8:
self.attack *= 50
enemy.hp -= self.attack
if enemy.hp < 0:
print(self.name,"对",enemy.name,"造成了【",self.attack,"】伤害,",enemy.name + '阵亡')
exit()
print("*" * 20)
print(self.name , "对" , enemy.name ,'发起攻击',","'造成' ,str(self.attack) ,'点伤害,',enemy.name,"还剩下",str(enemy.hp),"格血")
print("*" * 20)
class Player(Hero):
def __init__(self,name):
super().__init__(name,99)
self.attack = 55
print(self.name,"角色创建成功")
print("------------------")
print("血量为:",self.hp , "攻击力为:",self.attack, "等级为:",self.level)
yase = Hero("垭瑟",1000)
houyi= Player("后羿")
for i in range(10):
houyi.combat(yase)
yase.combat(houyi)
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