Maze.py
From WLCS
from MazeRoom import *
import random
class Maze:
numRows = 10
numCols = 10
rooms = []
def __init__(self, height=10, width=10):
self.numRows = height
self.numCols = width
for r in range(self.numRows):
roomRow = []
for c in range(self.numCols):
roomRow.append(MazeRoom(r, c))
self.rooms.append(roomRow)
def connectRooms(self, r1, r2):
# r1 is south of r2
if r1.row == r2.row+1 and r1.col == r2.col:
r1.roomToNorth=r2
r2.roomToSouth=r1
elif r1.row == r2.row-1 and r1.col == r2.col:
# r1 is north of r2
r2.roomToNorth=r1
r1.roomToSouth=r2
elif r1.row == r2.row and r1.col == r2.col+1:
#r1 is east of r2
r2.roomToEast=r1
r1.roomToWest=r2
elif r1.row == r2.row and r1.col == r2.col-1:
# r1 is east of r2
r1.roomToEast=r2
r2.roomToWest=r1
def isValidRoom(self, row, col):
# COMPLETE THE CODE
def getUnvisitedNeighbors(self, room):
# COMPLETE THE CODE
def countUnvisited(self):
# COMPLETE THE CODE
def generate(self):
# COMPLETE THE CODE
def print(self):
print(" _"*self.numCols)
for roomRow in self.rooms:
for room in roomRow:
if room.roomToWest == None:
print("|", end="")
else:
print(" ", end="")
if room.roomToSouth == None:
print("_", end="")
else:
print(" ", end="")
if room.col == self.numCols-1:
print("|")