本文整理汇总了Python中view.View.getBoardLoc方法的典型用法代码示例。如果您正苦于以下问题:Python View.getBoardLoc方法的具体用法?Python View.getBoardLoc怎么用?Python View.getBoardLoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类view.View
的用法示例。
在下文中一共展示了View.getBoardLoc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import getBoardLoc [as 别名]
class Game:
def __init__(self):
pg.init()
self.screen = pg.display.set_mode((settings.scr_width,settings.scr_height),settings.fullscreen)
pg.display.set_caption('BotSurvival!')
self.screen.fill(settings.back_color)
pg.display.update()
self.clock = pg.time.Clock()
self.restart()
def restart(self):
self.turn = 1
self.gamealive = True
self.board = HexBoard(settings.radius,(settings.map_size,settings.map_size))
self.board.padding = settings.padding
self.view = View(self.board.size,settings.view_height,settings.view_width)
self.draw_board()
self.bots = []
size = self.board.size[0]-1
for i in range(150):
x = int(floor(max(0,min(size,gauss(size/2,10)))))
y = int(floor(max(0,min(size,gauss(size/2,10)))))
self.bots.append((x,y))
pg.display.update()
while self.gamealive:
deltaTime = self.clock.tick(settings.fps)
pg.display.set_caption('BotSurvival! '+str(round(1.0/deltaTime*1000)))
self.dirty_rects = []
for event in pg.event.get():
if event.type == QUIT:
close()
elif event.type == MOUSEBUTTONDOWN:
self.run_turn()
self.turn += 1
elif event.type == KEYDOWN:
if event.key == K_r:
self.restart()
self.gamealive = False
elif event.key == K_ESCAPE:
close()
elif event.key == K_RIGHT:
self.view.move((0,2))
elif event.key == K_LEFT:
self.view.move((0,-2))
elif event.key == K_DOWN:
self.view.move((2,0))
elif event.key == K_UP:
self.view.move((-2,0))
self.draw_board()
self.draw_bots()
pg.display.update()
self.restart()
close()
def run_turn(self):
print self.turn
nl = []
self.erase_bots()
for loc in self.bots:
try:
nl.append(choice(self.board.locs_around(loc,['water','mountain'])))
except IndexError as err:
print err
self.bots = nl
self.draw_bots()
if self.turn >= settings.max_turns:
self.gamealive = False
def draw_board(self):
color = colors.gray5
size = self.view.getSize()
loc_list = ((x,y) for x in xrange(size[0]) for y in xrange(size[1]))
for vloc in loc_list:
#print self.board.map[loc]
bloc = self.view.getBoardLoc(vloc)
color = self.get_color(bloc)
self.draw_tile(vloc,color)
def draw_tile(self,loc,color,radius=settings.radius,contorno=True):
cpoint = self.board.centerPoint(loc)
hexa = drawing.hexagon(cpoint,radius)
pg.draw.polygon(self.screen,color,hexa)
if contorno:
pg.draw.lines(self.screen,colors.black,True,hexa,1)
def draw_bots(self):
for loc in self.bots:
vloc = self.view.getViewLoc(loc)
if vect.isInsideRect(vloc,self.view.getSize()):
self.draw_tile(vloc,colors.cyan5,settings.radius*0.6,False)
def erase_bots(self):
for loc in self.bots:
vloc = self.view.getViewLoc(loc)
if vect.isInsideRect(vloc,self.view.getSize()):
color = self.get_color(loc)
self.draw_tile(vloc,color)
#.........这里部分代码省略.........
示例2: abs
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import getBoardLoc [as 别名]
#Need further testing
dx = abs(loc2[1]-loc1[1])
dy = abs(loc2[0]-loc1[0])
l = [x for x in range(dy) if x%2==0]
if dx==0:
return dy
return dx+dy-min(dx,len(l))
#test
if __name__ == '__main__':
board = HexBoard(8,(51,51))
view = View(board.map)
vloc = (3,3)
bloc = view.getBoardLoc(vloc)
print board.loc_type(bloc)
view.move((5,5))
bloc = view.getBoardLoc(vloc)
print board.loc_type(bloc)