本文整理汇总了Python中inventory.Inventory.addWeapon方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.addWeapon方法的具体用法?Python Inventory.addWeapon怎么用?Python Inventory.addWeapon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.addWeapon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestInventory
# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import addWeapon [as 别名]
class TestInventory(unittest.TestCase):
"""
A test class for the Inventory module.
"""
def setUp(self):
"""
set up data used in the tests.
setUp is called before each test function execution.
"""
self.inv = Inventory()
self.weapon = Weapon("Canon", 20)
self.inv.addWeapon(self.weapon)
def testInitialized(self):
"""
Test if init goes good
"""
self.assertEqual(self.weapon.name, "Canon")
self.assertEqual(self.weapon.power, 20)
self.assertEqual(len(self.inv.weapons), 1)
self.assertEqual(self.inv.weapons[0], self.weapon)
示例2: Team
# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import addWeapon [as 别名]
class Team(pygame.sprite.Group):
"""
This is the team class, which is the owner of a group of snails.
Several snails together form a team.
"""
def __init__(self, name):
"""
Constructor to create a team of snails
@param name: The name of the team, which will displayed in various locations
@return: Team object.
"""
pygame.sprite.Group.__init__(self)
self.name = name
""" The name of the team"""
self.hasTurn = False
self.isAlive = True
self.orderedSnailList = []
self.gravity_direction = None
self.inventory = Inventory(self.name)
cannon = Cannon("Cannon", 20)
balloonLauncher = BalloonLauncher("Balloon", 30)
self.inventory.addWeapon(balloonLauncher)
self.inventory.addWeapon(cannon)
self.active_weapon = cannon
self.colorIndex = None
def update(self, *args):
"""
Call the update of all the objects the team currently manages, this can include weapon, inventory and snails.
@param *args: Pass all the arguments to the the update of the sprites.
"""
pygame.sprite.Group.update(self,*args)
self.checkAlive()
if(self.inventory.visible and self.hasTurn):
tempWeapon = self.inventory.update(args[0])
if(not None == tempWeapon):
self.active_weapon = tempWeapon
if(not None == self.active_weapon):
self.active_weapon.update(*args)
def draw(self, surface):
"""
Draw all the objects the team currently manages, this can include weapon, inventory and snails.
@param surface: This is the surface created in the game class
"""
for sprite in self:
sprite.draw(surface)
#draw the inventory if team has turn
if(self.hasTurn):
self.active_weapon.draw(surface)
self.inventory.draw(surface)
if self.hasTurn and not None == self.active_weapon:
for snail in self.orderedSnailList:
if snail.hasTurn == True:
self.active_weapon.snail_rect = snail.rect
def addSnails(self, numberOfSnails):
"""
Add a number of snails to the teams, this creates snails objects.
"""
for i in range(0, numberOfSnails):
snail = Snail(self)
snail.id = i
self.add(snail)
self.orderedSnailList.append(snail)
self.orderedSnailList[len(self.orderedSnailList) - 1].hasTurn = True
def setGravity(self, direction):
"""
Set the gravity direction for the team
@param direction: An integer representing a value. Use enums.Direction.
"""
self.gravity_direction = direction
for s in self.sprites():
s.gravity_direction = direction
def setTeamImage(self, imageNumber):
"""
sets the image of the team using a number
the sprite's folder contains snails with 4 different colors
the number given will be used to select a different snail
"""
self.colorIndex = imageNumber
#.........这里部分代码省略.........