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


Python Inventory.debug方法代码示例

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


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

示例1: Game

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import debug [as 别名]
class Game(object):
	"""
	"""
	def __init__(self, wnd, w, h):
		"""
		"""
		Database.init()
		self.hexa_size = 80
		self.width = w
		self.height = h
		self.canvas = Canvas(
			wnd, width=self.width, height=self.height,
			bg='#0080FF', highlightthickness=0, bd=0)
		self.canvas.pack()
		wnd.resizable(False, False)
		self.player = Player(1)
		self.inventory = Inventory()
		self.hexagons = []
		self.defaultBoardArgs = (2, 3, True)

		self.canvas.tag_bind('hexagon', "<Button-1>", self.hexAction)

		# TODO : Remove these tests
		self.player.debug()
		Database.debug_items()
		self.inventory.addItem(0)
		self.inventory.addItem(1)
		self.inventory.addItem(0)
		self.inventory.addItem(2)
		self.inventory.addItem(0)
		self.inventory.debug()
		Database.debug_enemies()

	def hexAction(self, event):
		tmp = self.canvas.find_withtag(CURRENT)
		if tmp:
			id = tmp[0]
			index = self.getHexIndexByID(id)
			if self.hexagons[index].hasTag('Player'):
				print("Action: Open Inventory")
			elif self.hexagons[index].hasTag('Enemy'):
				print("Action: Attack")
			else:
				print("Action: Move")
				movePos = self.hexagons[index].position
				if movePos[0] == 0 and movePos[1] == 0:
					return
				def move(t, nIndex):
					self.hexagons[nIndex].setEntity(t.entity)
					t.unsetEntity()

				move(self.hexagons[self.getPlayerHexIndex()], index)
				doneIDs = []
				def moveUtil(t):
					nPos = [t.position[0] - movePos[0], t.position[1] - movePos[1]]
					if nPos[0] % 2 and not t.position[0] % 2:
						nPos[1] -= 1
					nPos = tuple(nPos)
					nIndex = self.getHexIndexByPosition(nPos)
					if nIndex == -1:
						if not((nPos[0] < t.position[0] and nPos[1] < t.position[0]) or (nPos[0] > t.position[0] and nPos[1] == t.position[1])):
							t.unsetEntity()
						doneIDs.append(t.id)
						return
					if not nIndex in doneIDs:
						moveUtil(self.hexagons[nIndex]) # Bad recursion... but works with small boards
					move(t, nIndex)
					doneIDs.append(t.id)
				for t in self.hexagons:
					if t.id in doneIDs:
						continue
					moveUtil(t)

	def getBoardWidth(self, row=-1):
		return self.defaultBoardArgs[1]

	def getBoardHeight(self, column):
		# This code is a bit tricky
		# Since the board is composed of hexagons
		# The height isn't the same on every row
		# (at least that's how we handled everything)
		# We use the self.defaultBoardArgs
		# Basically, it'll handle the board's form
		# If self.defaultBoardArgs[2] is True, then the first
		# column will have the lowest number
		# of rows, eg. if self.defaultBoardArgs[0] is set to 2
		# then the first column will have 2 rows
		# The other columns have 1 more row
		# The best way to understand is to try it x)
		n = 0
		if column % 2 :
			if self.defaultBoardArgs[2]:
				n = self.defaultBoardArgs[0] + 1
			else:
				n = self.defaultBoardArgs[0]
		else:
			if self.defaultBoardArgs[2]:
				n = self.defaultBoardArgs[0]
			else:
				n = self.defaultBoardArgs[0] + 1
#.........这里部分代码省略.........
开发者ID:Tidaren,项目名称:ISN,代码行数:103,代码来源:game.py


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