Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

bellcode / lesson8-2

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • lesson8-2
  • diy1.py
Find file
BlameHistoryPermalink
  • BellCodeEditor's avatar
    save project · 2e3dceb6
    BellCodeEditor committed 3 months ago
    2e3dceb6
diy1.py 900 Bytes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
class Hero:
    def __init__(self, name):
        self.level = 1
        self.hp = 250
        self.attack = 40
        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()
class player(Hero)
    def _init_(self, name,):
        super().__init__(name)
        self.hp=200
        self.attack=50
houyi= Hero("后羿")
print("玩家的血量浙外",player.he)
print("玩家的攻击了为",player.attack)