本文整理汇总了Python中map.Map.neighborAt方法的典型用法代码示例。如果您正苦于以下问题:Python Map.neighborAt方法的具体用法?Python Map.neighborAt怎么用?Python Map.neighborAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map.Map
的用法示例。
在下文中一共展示了Map.neighborAt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import neighborAt [as 别名]
class Game(object):
def __init__(self):
self.turn =1
#Create debugging display
debug_win = uc.newwin(15, 30, 0, 0)
uc.box(debug_win)
uc.wmove(debug_win, 1, 1)
uc.waddstr(debug_win, "Debug:")
uc.wmove(debug_win, 2, 1)
debug_pnl = uc.new_panel(debug_win)
uc.move_panel(debug_pnl, glob.CAM_HEIGHT, 32)
#Generate the world
self.world = Map(glob.N_HEX_ROWS, glob.N_HEX_COLS, debug_win)
#map_height: 3 + 2*(rows-1) + 2 for border
#map_width: 5 + 4*cols + 2 for border
map_win = uc.newwin(glob.CAM_HEIGHT, glob.CAM_WIDTH, 0, 0)
self.painter = Painter(glob.N_HEX_ROWS, glob.N_HEX_COLS, map_win)
self.painter.updateAllTiles(self.world)
#Put world window into a panel
map_pnl = uc.new_panel(map_win)
uc.move_panel(map_pnl, 1, 1)
uc.top_panel(debug_pnl)
self.status_win = uc.newwin(10, 30, 0, 0)
uc.box(self.status_win)
uc.wmove(self.status_win, 1, 1)
uc.waddstr(self.status_win, "Turn " + str(self.turn))
status_pnl = uc.new_panel(self.status_win)
uc.move_panel(status_pnl, glob.CAM_HEIGHT, 2)
self.tile_window = TileWindow()
self.painter.drawWindow()
showChanges()
#input loop
while True:
sys.stdout.flush()
ch = uc.getch()
uc.waddstr(debug_win, str(ch))
#Exit Key
if ch == Key.ESC:
break
#Movement Keys
elif ch == Key.E:
self.movePlayer(HexDir.UL)
elif ch == Key.R:
self.movePlayer(HexDir.UR)
elif ch == Key.S:
self.movePlayer(HexDir.L)
elif ch == Key.G:
self.movePlayer(HexDir.R)
elif ch == Key.D:
self.movePlayer(HexDir.DL)
elif ch == Key.F:
self.movePlayer(HexDir.DR)
#End Turn Key
elif ch == Key.SPACE:
self.incrementTurn()
#Camera Scrolling Keys
#TBD: Remaining order checks
elif ch == uc.KEY_UP:
self.painter.moveCamera(0, -1*glob.CAM_SPEED)
elif ch == uc.KEY_DOWN:
self.painter.moveCamera(0, glob.CAM_SPEED)
elif ch == uc.KEY_LEFT:
self.painter.moveCamera(-1*glob.CAM_SPEED, 0)
elif ch == uc.KEY_RIGHT:
self.painter.moveCamera(glob.CAM_SPEED, 0)
#Toggle drawing borders
elif ch == Key.B:
self.painter.draw_borders = not self.painter.draw_borders
self.painter.updateAllTileBorders(self.world)
self.painter.drawWindow()
#TODO: This needs to become moveCursor
def movePlayer(self, dir):
for tile in self.world.tiles:
if tile.has_player:
pos_x, pos_y = tile.pos
break
_pos = self.world.neighborAt(pos_x, pos_y, dir)
if _pos:
_tile = self.world.tileAt(_pos[0], _pos[1])
if _tile.terrain != Terrain.WATER:
tile = self.world.tileAt(pos_x, pos_y)
#.........这里部分代码省略.........