-
Notifications
You must be signed in to change notification settings - Fork 0
/
mazeview.py
55 lines (48 loc) · 1.97 KB
/
mazeview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Name: Leigh Stauffer
Project 6
Author: Kenneth A. Lambert
File: mazeview.py
"""
from breezypythongui import EasyFrame
from mazesquare import MazeSquare
from mazemodel import MazeModel
from grid import Grid
import sys
class MazeView(EasyFrame):
"""GUI-based maze program."""
def __init__(self, model):
"""Sets up the window, label, and buttons."""
EasyFrame.__init__(self, "An Amazin' Maze")
self.model = model
# Add maze squares to the grid
self.squares = Grid(self.model.getHeight(), self.model.getWidth())
for row in range(0, self.squares.getHeight()):
for column in range(0, self.squares.getWidth()):
square = MazeSquare(self, width = 20, height = 20,
letter = self.model.getLetter(row, column))
square = self.addCanvas(canvas = square,
row = row, column = column)
self.squares[row][column] = square
self.moveButton = self.addButton(text = "Move",
row = self.model.getHeight(),
column = 0, columnspan = self.model.getWidth(),
command = self.move)
def move(self):
row, column = self.model.move()
self.squares[row][column].setLetter(self.model.getLetter(row, column))
if self.model.isSolved():
self.moveButton["state"] = "disabled"
self.messageBox(title = "ALERT", message = "Maze solved")
elif not self.model.canMove():
self.moveButton["state"] = "disabled"
self.messageBox(title = "ALERT", message = "Maze can't be solved")
def main(fileName = "maze1.txt"):
"""Starting point for the app."""
if len(sys.argv) > 1:
fileName = sys.argv[1]
model = MazeModel(fileName)
MazeView(model).mainloop()
# Instantiates and pops up the window.
if __name__ == "__main__":
main()