建网站需要什么技术,网站建设学习什么,免费设计图片素材网站,丹阳企业网站制作需求#xff1a;狙击手xxx使用xx枪#xff0c;射击敌人xxx,敌人生命值归0#xff0c;应声倒下分析设计类#xff1a; 封装狙击手类 属性#xff1a; 名字 行为#xff1a;捡枪 装弹 射击封装枪类 属性#xff1a; 型号 行为#xff1a;射击封装弹夹类 属性狙击手xxx使用xx枪射击敌人xxx,敌人生命值归0应声倒下分析设计类 封装狙击手类 属性 名字 行为捡枪 装弹 射击封装枪类 属性 型号 行为射击封装弹夹类 属性弹夹容量 存储子弹的列表封装子弹类 属性伤害值 移动速度 行为移动封装敌人类 属性名称 生命值 #狙击手类
class Sniper:def __init__(self,name):self.name name# self.gun None#捡枪def pickupGun(self):gun Gun(AWM)#给对象添加一个gun的属性self.gun gun#装弹def loading(self):#创建一个弹容量为10的弹夹clip Clip(10)for i in range(clip.capacity):bullet Bullet()#循环装子弹clip.bullet_list.append(bullet)#给你拥有的枪添加一个属性self.gun.clip clip#射击敌人def shoot(self,enemy):print({}瞄准{}进行射击.format(self.name,enemy.name))self.gun.shoot(enemy)
#枪类
class Gun:def __init__(self,type):self.type type#枪的射击功能def shoot(self,enemy):while enemy.hp 0:# 将子弹从弹夹中移除bullet self.clip.bullet_list.pop()enemy.hp - bullet.damageif enemy.hp 0:bullet.move()print(敌人{}应声倒下.format(enemy.name))
#弹夹类
class Clip:def __init__(self,capacity):#弹夹容量self.capacity capacity#用来存储子弹的列表self.bullet_list []
#子弹类
class Bullet:def __init__(self):self.damage 100self.speed 1000def move(self):print(子弹以{}m/s向敌人.format(self.speed))
#敌人类
class Enemy:def __init__(self,name,hp):self.name nameself.hp hp#创建狙击手对象
sniper Sniper(海豹突击1号)
#狙击手捡枪
sniper.pickupGun()
# print(dir(sniper))
# print(dir(sniper.gun))
#装弹
sniper.loading()
# print(dir(sniper.gun))
# #打印狙击手的枪的弹夹的子弹列表中的子弹
# print(sniper.gun.clip.bullet_list)
# #创建敌人对象
enemy Enemy(小日本1,100)
#射击
sniper.shoot(enemy)
print(枪中剩余子弹{}发.format(len(sniper.gun.clip.bullet_list)))转载于:https://www.cnblogs.com/ilovepython/p/11068889.html