python类之间相互调用_不同Python类之间的调用,python

#coding=utf-8

class Guns(object):

def __init__(self):

self.type = "M16"

self.bulletnum = 30

self.harm = 50

def show_info(self):

print 'the gunInfo type is:%s,bulletnum is:%s,harm is:%s' % (self.type, self.bulletnum, self.harm)

def add_bullet(self, k=5):

for v in xrange(k):

self.bulletnum += 30

print 'the gun bulletnum is:%d,now!' % self.bulletnum

class Person(object):

def __init__(self):

self.name = 'player1'

self.blood = 100

self.position = (0, 0)

self.harm_people = []

self.gun = Guns()

def get_a_gun(self,gun):

# print 'get a gunInfo is:%s,%s,%s' %(gun.type,gun.bulletnum,gun.harm)

gun.show_info()

class Police(Person):

def __init__(self):

Person.__init__(self)

self.name = 'Police'

self.kill_index = 0

self.pers = Thief()

def shoot(self,gun,pers):

if gun.bulletnum < 150:

gun.add_bullet()

#开始开火

gun.bulletnum -= 1

pers.blood -= gun.harm

if pers.blood <= 0:

pers.isDead = True

pers.killed_index += 1

self.kill_index += 1

self.harm_people.append(pers.name)

print 'kill_index is:%d,harm_people is:%s' %(self.kill_index,self.harm_people)

return self.kill_index,self.harm_people

class Thief(Person):

def __init__(self):

Person.__init__(self)

self.name = 'thief'

self.killed_index = 0

self.isDead = False

def show_thief_info(self):

print 'thief blood is:%d,isDead is:%s,killed_index is:%d' %(self.blood,self.isDead,self.killed_index)

g = Guns()

p1 = Thief()

pers = Police()

def mainRun(g,p1):

for x in xrange(10):

p1.get_a_gun(g)

p1.show_thief_info()

if p1.isDead:

print "the Thief has dead, stop shoot"

break

else:

pers.shoot(g,p1)

mainRun(g,p1)

#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值