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


Python Ship.squares方法代码示例

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


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

示例1: populate_bg

# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import squares [as 别名]
	def populate_bg(self, bg):
		"""
		Populate a battleground with random ships.
		:param bg: the battleground to populate
		"""
		it = SHIP_LENS.__iter__()
		ship_len = it.next()
		while True:
		#for ship_len in SHIP_LENS:
			ship = Ship(ship_len)
			direction = random.randint(0, 1) # 0 = vertical, 1 = horizontal
			if direction == 0:
				start_x = random.randint(0, NUM_SQUARES - 1)
				start_y = random.randint(0, NUM_SQUARES - 1 - ship_len)
			elif direction == 1:
				start_x = random.randint(0, NUM_SQUARES - 1 - ship_len)
				start_y = random.randint(0, NUM_SQUARES - 1)

			squares = []
			for i in xrange(ship_len):
				if direction == 0:
					squares.append(Square(start_x, start_y + i, SquareState.intact))
				elif direction == 1:
					squares.append(Square(start_x + i, start_y, SquareState.intact))

			ship.squares = squares
			if bg.check_intersect(ship):
				continue
			bg.add_ship(ship)

			# Python's fucked up way to check if an iterator reached the end of a container
			try:
				ship_len = it.next()
			except:
				break
开发者ID:rakibuiu,项目名称:battleship-leap-python,代码行数:37,代码来源:main.py


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