本文整理汇总了Python中maze.Maze.repaint方法的典型用法代码示例。如果您正苦于以下问题:Python Maze.repaint方法的具体用法?Python Maze.repaint怎么用?Python Maze.repaint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maze.Maze
的用法示例。
在下文中一共展示了Maze.repaint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import repaint [as 别名]
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setWindowTitle("Bomb Seekerz")
self.init_maze()
def init_maze(self):
# custom map is a list containing each row
# and the width is the length of the first row
custom_map = []
f = open('map.txt', 'r')
for line in f.readlines():
custom_map.append(line)
f.close()
width = len(custom_map[0])
height = len(custom_map)
self.maze = Maze(width, height, custom_map)
hbox = QHBoxLayout()
hbox.setContentsMargins(0, 0, 10, 0)
hbox.addWidget(self.maze)
vbox = QVBoxLayout()
vbox.setContentsMargins(0, 10, 0, 0)
hbox.addLayout(vbox)
self.agents = QLineEdit("s")
vbox.addWidget(QLabel("agent to watch:"))
vbox.addWidget(self.agents)
self.btn_watch = QPushButton("Watch Agent")
self.btn_watch.clicked.connect(self.watchAgent)
vbox.addWidget(self.btn_watch)
self.btn_remove = QPushButton("Remove path")
self.btn_remove.clicked.connect(self.remove)
vbox.addWidget(self.btn_remove)
self.btn_solve = QPushButton("Start")
self.btn_solve.clicked.connect(self.startSolving)
vbox.addWidget(self.btn_solve)
self.btn_step = QPushButton("Next Step")
self.btn_step.clicked.connect(self.doStep)
vbox.addWidget(self.btn_step)
self.btn_stop = QPushButton("Stop")
self.btn_stop.setEnabled(False)
self.btn_stop.clicked.connect(self.stopSolving)
vbox.addWidget(self.btn_stop)
self.btn_restart = QPushButton("Restart")
self.btn_restart.setEnabled(True)
self.btn_restart.clicked.connect(self.restart)
vbox.addWidget(self.btn_restart)
vbox.addStretch()
proxy_widget = QWidget()
proxy_widget.setLayout(hbox)
self.setCentralWidget(proxy_widget)
self.maze.init()
def watchAgent(self):
if self.agents.displayText() == 's':
for a in self.maze.agents:
if a.is_scout:
agent = a
break
else:
try:
agent = self.maze.agents[int(self.agents.displayText())-1]
except:
return True
for a in self.maze.agents:
if a.draw_path:
a.draw_path = False
agent.draw_path = True
def remove(self):
for a in self.maze.agents:
if a.draw_path:
a.draw_path = False
def restart(self):
self.Maze = None
self.init_maze()
def doStep(self):
if self.maze.stop_parent:
self.stopSolving()
self.maze.step_num += 1
for a in self.maze.agents:
a.move()
self.maze.repaint()
def startSolving(self):
self.btn_solve.setEnabled(False)
#.........这里部分代码省略.........