当前位置: 首页>>代码示例>>Python>>正文


Python Inventory.add_to_inventory方法代码示例

本文整理汇总了Python中inventory.Inventory.add_to_inventory方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.add_to_inventory方法的具体用法?Python Inventory.add_to_inventory怎么用?Python Inventory.add_to_inventory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inventory.Inventory的用法示例。


在下文中一共展示了Inventory.add_to_inventory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Game

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import add_to_inventory [as 别名]
class Game(object):
	## MAIN GAME CLASS
	def __init__(self):
		# init pygame and abstract classes
		self.clock = pygame.time.Clock()
		self.screen = Screen()
		self.gamemap = GameMap()

		# init game state
		self.game_state = 'PREPARING'
	
		# create player paddle and inventory
		self.player = Player(100, 50, 50)
		self.inventory = Inventory()

		# create sprite Groups for game logic
		self.player_list = pygame.sprite.Group()
		self.weapon_list = pygame.sprite.Group()
		self.expReward_list = pygame.sprite.Group()

		self.player_list.add(self.player)	

		# sword swing int
		self.sword_count = 0
	
		# invulnerability timer
		self.invuln_count = 0
		
		# create rooms
		# there has to be a better way
		self.rooms = self.gamemap.get_rooms()
		
		self.current_room_num = 0
		self.current_room = self.rooms[self.current_room_num]

		# define default weapon type
		self.combat = Combat(self.player,self.weapon_list,self.current_room.wall_list,
			self.current_room.enemy_list, self.current_room.treasure_list, self.expReward_list)
		
		self.run()

	def terminate(self):
		pygame.quit()
		sys.exit()

	def run(self):
		self.screen.to_screen(self.current_room.wall_list, self.screen.mapSurf)

		self.game_state = 'RUNNING'	
		while 1:		
			self.clock.tick(60)
			# event processing
		
			for event in pygame.event.get():
				if event.type == pygame.QUIT:
					self.terminate()
			
				if event.type == pygame.KEYDOWN:
					self.keyboardDown(event)
						
				if event.type == pygame.KEYUP:
					self.keyboardUp(event)
					
			# game logic

			if self.game_state == 'RUNNING':
		
				self.gameplay_modelUpdate()
				self.gameplay_viewerUpdate(self.screen)
			
		pygame.quit()

	def add_treasure(self, treasure):
		text = 'You found %s. %s' % (treasure.title, treasure.desc)
		self.inventory.add_to_inventory(treasure, self.player)
	#	self.screen.draw_alert(text)

	def blit_alpha(self, target, source, location, opacity):
		x = location[0]
		y = location[1]
		temp = pygame.Surface((source.get_width(), source.get_height())).convert()
		temp.blit(target, (-x, -y))
		temp.blit(source, (0, 0))
		temp.set_alpha(opacity)        
		target.blit(temp, location)
		
	def keyboardDown(self, evt):
		if evt.key == pygame.K_ESCAPE:
			self.doMenu()
		if self.game_state == 'RUNNING':
			if evt.key == pygame.K_LCTRL:
				self.combat.weaponSelect()
			if evt.key == pygame.K_LEFT:
				self.player.change_speed(-5, 0)
			if evt.key == pygame.K_RIGHT:
				self.player.change_speed(5, 0)
			if evt.key == pygame.K_UP:
				self.player.change_speed(0, -5)
			if evt.key == pygame.K_DOWN:
				self.player.change_speed(0, 5)
#.........这里部分代码省略.........
开发者ID:McWenker,项目名称:DE,代码行数:103,代码来源:game.py

示例2: __init__

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import add_to_inventory [as 别名]
class Player:

    def __init__(self):
        """
        Initializing our player with his initial stats
        These are what I feel players should start out with
        Hans' stats vary within the game
        :return:
        """
        self.level = 1
        self.stats = {'str': 12, 'mag': 1, 'skill': 13, 'spd': 13, 'def': 15, 'lck': 12, 'res': 4}
        self.growths = {'hp': 0.8, 'str': 0.6, 'mag': 0.2, 'skill': 0.7, 'spd': 0.7, 'def': 0.6, 'luk': 0.3, 'res': 0.3}
        self.hp = 30
        self.max_hp = 30
        self.name = "Hans"
        self.inventory = Inventory()
        self.equipped = self.inventory.get_specific_item("Steel Axe")
        self.loc = (1, 1)

    def receive_damage(self, damage):
        """
        Receiving damage to the player
        :param damage: total damage being received
        :return:
        """
        dmg = max(0, damage - self.stats['def'])
        self.hp = max(0, self.hp-dmg)

    def attack(self, defense):
        """
        Returns the damage dealt to an enemy
        If the player is not equipped with anything, simply return 0
        :param def: opposing enemy's def
        :return: damage dealt
        """
        if self.equipped:
            return self.stats['str'] + self.equipped.mt - defense
        return 0

    def equip_item(self, item):
        """
        Equips an item. Has to be a weapon
        :param item: weapon to equip
        :return:
        """
        if isinstance(item, Weapon) and item.name in self.inventory.get_items():
            self.equipped = item

    def add_to_inventory(self, item):
        """
        Adds an item to the inventory
        Following Fates, we only allow 5 item slots
        :param item: item to add to inventory
        :return:
        """
        return self.inventory.add_to_inventory(item)

    def remove_from_inventory(self, item):
        """
        Removes an item from an inventory
        TODO: find a good way to remove an item after using a healing item
        :param item: item to be removed
        :return:
        """
        if item.name in self.inventory.get_items():
            self.inventory.remove_from_inventory(item)

    def inc_max_hp(self, amount):
        """
        Increases the max hp, mostly from leveling up or items
        :param amount: amount to increase by
        :return:
        """
        self.max_hp += amount

    def use_item(self, item):
        """
        Usage of an item, must not be a weapon
        :param item:
        :return:
        """
        if item.name in self.inventory.get_items():
            if item.usage == "HEALING":
                self.hp = min(self.max_hp, self.hp+item.amount)
            if item.usage == "SERAPH":
                self.inc_max_hp(item.amount)

    def set_location(self, location):
        """
        Sets the location of the player
        :param location: location to set
        :return:
        """
        self.loc = location
开发者ID:dguan4,项目名称:HanStory,代码行数:96,代码来源:player.py


注:本文中的inventory.Inventory.add_to_inventory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。