zoukankan      html  css  js  c++  java
  • 依赖关系

    # class Person:
    #     def play(self, tools): # 通过参数的传递把另外一个类的对象传递进来
    #         tools.run()
    #         print("很开心, 我能玩儿游戏了")
    #
    #
    # class Computer:
    #     def run(self):
    #         print("电脑开机. 可以运行")
    #
    # class Phone:
    #     def run(self):
    #         print("手机开机, 可以运行")
    #
    #
    # c = Computer()
    # phone = Phone()
    #
    # p = Person()
    # p.play(phone)
    
    
    
    # 写一个植物大战僵尸
    # 1. 植物
    #       打僵尸. 僵尸掉血
    # 2. 僵尸
    #       吃植物. 植物掉血
    
    class Plant:
        def __init__(self, name, hp, ad): # 200
            self.name = name
            self.hp = hp
            self.ad = ad
    
        def attack(self, js):
            print("植物攻击僵尸")
            js.hp -= self.ad
            print(f"僵尸掉血{self.ad}, 还剩下{js.hp}")
    
    class JiangShi:
        def __init__(self, name, hp, ad): # 1000  800
            self.name = name
            self.hp = hp
            self.ad = ad
    
        def attack(self, zw):
            print("僵尸咬植物")
            zw.hp -= self.ad
            print(f"植物掉血{self.ad}, 还剩{zw.hp}")
    
    
    # 植物
    wd = Plant("歪脖子豌豆", 10, 20)
    # 僵尸
    js = JiangShi("铁桶僵尸", 200, 1)
    wd.attack(js)
    wd.attack(js)
    wd.attack(js)
    wd.attack(js)
    wd.attack(js)
    
    js.attack(wd)
    js.attack(wd)
    js.attack(wd)
    js.attack(wd)
    

      

  • 相关阅读:
    使用jxl.jar操作Excel
    ThreadLocal学习
    ArrayList与Vector、HashMap与HashTable
    String, StringBuffer, StringBuilder比较
    ArrayList与LinkedList实现比较
    Java文件备份类
    Maven安装与更新
    Eclipse安装反编译工具JadClipse
    Linux关闭防火墙
    Hadoop简介
  • 原文地址:https://www.cnblogs.com/work14/p/10145463.html
Copyright © 2011-2022 走看看