Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Maze:
- """A 2D Maze"""
- """The Maze constructor
- (none) -> none
- start by declaring attributes"""
- def __init__(self):
- self.mazeIndex = 0
- self.mazes = []
- self.initMazes()
- self.currentMaze = self.mazes[0]
- def toString(self):
- printme = ""
- """for i in range (0, len(self.currentMaze.tiles)):
- for j in self.currentMaze.tiles[i]:
- printme = printme + j"""
- return printme
- def initMazes(self):
- self.mazes.append({"tiles": [['#', '#', '#', '#', '#', '#', '#'],
- ['#', ' ', '#', ' ', ' ', ' ', '#'],
- ['#', ' ', '#', ' ', ' ', ' ', '#'],
- ['#', ' ', '#', ' ', '#', '#', '#'],
- ['#', ' ', '#', ' ', ' ', '@', '#'],
- ['#', ' ', ' ', ' ', ' ', ' ', '#'],
- ['#', '#', '#', '#', '#', '#', '#']],
- "sprouts": 1, "width": 7, "height": 7}
- )
- # Set the current maze to level 1
- self.mazes.append({"tiles": [['#', '#', '#', '#', '#'],
- ['#', ' ', ' ', ' ', '#'],
- ['#', '@', ' ', ' ', '#'],
- ['#', ' ', ' ', '@', '#'],
- ['#', '#', '#', '#', '#']],
- "sprouts": 2, "width": 5, "height": 5}
- )
- def placeRat(self, rat_char, row, column):
- self.currentMaze.tiles[row][column] = rat_char
- def clearAtPos(self, row, col):
- self.currentMaze.tiles[row][col] = " "
- def eatSprouts(self):
- self.currentMaze.sprouts -= 1
- if self.currentMaze.sprouts == 0:
- self.mazeIndex += 1
- # Here we check if mazeIndex is equal to len(mazes), in which case there are no more mazes
- if self.mazeIndex == len(mazes):
- print("You win!")
- # Else, if there are more levels, set the next one as the current maze
- else:
- self.currentMaze = self.mazes[self.mazeIndex]
- def getWidth(self):
- return self.currentMaze.width
- def getHeight(self):
- return self.currentMaze.height
- def getCharAtPos(self, row, col):
- return self.currentMaze.tiles[row][col]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement