Commit 58b0aacf by BellCodeEditor

save project

parent f0e4c539
Showing with 7 additions and 17 deletions
import random
class Hero(object):
def __init__(self, name,hp):
self.level = 1
......@@ -6,32 +5,22 @@ class Hero(object):
self.attack = 40
self.name = name
def combat(self,enemy):
x = random.randint(1,10)
if x >8:
self.attack *= 50
def combat(self,enemy):
enemy.hp -= self.attack
if enemy.hp < 0:
print(self.name,"对",enemy.name,"造成了【",self.attack,"】伤害,",enemy.name + '阵亡')
print(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)
yase = Hero("垭瑟",130)
houyi= Player("后羿")
for i in range(10):
houyi.combat(yase)
yase.combat(houyi)
houyi.combat(yase)
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