反恐精英代码(cs反恐精英代码)

  • 生活
  • 2023-04-19 13:50

废话不多说

上代码

#CS反恐精英1.0

#1、定义战士和敌人的类

classPerson:

"""人的属性"""

def__init__(self,name):

"""姓名"""

self.name=name

"""血量"""

self.blood=100

"""人的***"""

"""给弹夹安装子弹"""

definstall_bullet(self,clip,bullet):

"""弹夹放置子弹"""

clip.save_bullets(bullet)

"""给抢安装弹夹"""

definstall_clip(self,gun,clip):

gun.mounting_clip(clip)

"""持枪"""

deftake_gun(self,gun):

self.gun=gun

"""开枪"""

deffire(self,enemy):

"""射击敌人"""

self.gun.shoot(enemy)

def__str__(self):

returnself.name+"剩余血量为:"+str(self.blood)

"""掉血"""

deflose_blood(self,damage):

self.blood-=damage

"""定义表示弹夹的类"""

classClip:

def__init__(self,capacity):

"""最大容量"""

self.capacity=capacity

"""当前容量"""

self.current_list=[]

"""安装子弹"""

defsave_bulllets(self,bullet):

"""当前子弹数量小于最大容量"""

iflen(self.current_list)<self.capacity:

self.current_list.append(bullet)

"""构造一个函数,返回现在的弹夹数量"""

def__str__(self):

return"弹夹当前的子弹数量为:"+str(len(self.current_list))+"/"+str(self.capacity)

"""出子弹"""

deflaunch_bullet(self):

iflen(self.current_list)>0:

bullent=self.current_list[-1]

self.current_list.pop()

returnbullet

else:

returnNone

"""定义表示子弹的类"""

classBullet:

def__init__(self,damage):

"""伤害力"""

self.damage=damage

"""伤害敌人"""

defhurt(self,enemy):

"""让敌人掉血"""

enemy.lose_blood(self.damage)

"""定义抢的类"""

classGun:

def__init__(self):

"""默认没有弹夹"""

self.clip=None

def__str__(self):

ifself.clip:

return"枪当前有弹夹"

else:

return"枪没有弹夹"

"""链接弹夹"""

defmounting_clip(self,clip):

ifnotself.clip:

self.clip=clip

"""射击"""

defshoot(self,enemy):

bullet=self.launch_bullet()

"""射击未击中"""

ifbullet:

bullet.hurt(enemy)

else:

print('没有子弹了,放了空枪。。。。')

"""创建一个战士"""

soldier=Person("老王")

"""创建一个敌人"""

enemy=Person('敌人')

"""创建一个枪"""

gun=Gun()

print(enemy)

"""士兵拿枪"""

soldier.take_gun(gun)

"""士兵开枪"""

soldier.fire(enemy)

"""创建一个弹夹"""

clip=Clip(20)

"""创建一个子弹"""

bullet=Bullet(5)

"""战士安装子弹到弹夹"""

soldier.install_bullet(clip,bullet)

soldier.install_bullet(gun,clip)

"""输出当前弹夹中子弹的数量"""

print(clip)

print(gun)

print(clip)

print(enemy)

soldier.install_clip(gun,clip)

print(clip)

print(enemy)

猜你喜欢