Question
Creating a maze stimulation in python 3!!! The maze will be based on linked lists. A room will be the basic object for the maze
Creating a maze stimulation in python 3!!!
The maze will be based on linked lists. A room will be the basic object for the maze game. A room can have 4 doors (pertaining to north, south, east, and west). Attached to each of these directions have either another room or None (we could also imagine that the None doors are just walls). The player has to be able to tell what room they are in. Each room will have a unique description. When the player enters a room, the program will describe the room. This way the player will know if they went back to a room that they have already been to.
Here is the room class:
class Room:
#Constructor sets the description
#All four doors should be set to None to start
def __init__(self,descr):
#Description of the room to print out
#These should be unique so the player knows where they are
self.__descr = descr
#These either tell us what room we get to if we go through the door
#or they are None if the "door" can't be taken.
self.__north = None
self.__south = None
self.__east = None
self.__west = None
#Access
#Return the correct values
def __str__(self):
#Implement Me
def getNorth(self):
#Implement Me
def getSouth(self):
#Implement Me
def getEast(self):
#Implement Me
def getWest(self):
#Implement Me
#Mutators
#Update the values
def setDescription(self,d):
#Implement Me
def setNorth(self,n):
#Implement Me
def setSouth(self,s):
#Implement Me
def setEast(self,e):
#Implement Me
def setWest(self,w):
#Implement Me
Maze class:
class Maze:
#Inputs: Pointer to start room and exit room
#Sets current to be start room
def __init__(self,st=None,ex=None):
#Room the player starts in
self.__start_room = st
#If the player finds this room they win
self.__exit_room = ex
#What room is the player currently in
self.__current = st
#Return the room the player is in (current)
def getCurrent(self):
#Implement Me
#The next four all have the same idea
#See if there is a room in the direction
#If the direction is None, then it is impossible to go that way
#in this case return false
#If the direction is not None, then it is possible to go this way
#Update current to the new move (move the player)
#then return true so the main program knows it worked.
def moveNorth(self):
#Implement Me
def moveSouth(self):
#Implement Me
def moveEast(self):
#Implement Me
def moveWest(self):
#Implement Me
#If the current room is the exit,
#then the player won! return true
#otherwise return false
def atExit(self):
#Implement Me
#If you get stuck in the maze, you should be able to go
#back to the start
#This sets current to be the start_room
def reset(self):
#Implement Me
To connect all the rooms (put them into a list of reference variables):
my_rooms = [] my_rooms.append(Room("This room is the entrance.")) my_rooms.append(Room("This room has a table. Maybe a dinning room?")) my_rooms.append(Room("This room is the exit. Good Job.")) #room 0 is south of room 1 my_rooms[0].setNorth(my_rooms[1]) my_rooms[1].setSouth(my_rooms[0]) #Room 2 is east of room 1 my_rooms[1].setEast(my_rooms[2]) my_rooms[2].setWest(my_rooms[1])
my_maze = Maze(my_rooms[0],my_rooms[2])
Create an interface for the player. Print a description of the room. Next, ask the player what direction to move. Either move into the next room, or stay in the same place if the path is blocked.
Here is an example walk through the above maze.
This room is the entrance. Enter direction to move north west east south restart west Direction invalid, try again. This room is the entrance. Enter direction to move north west east south restart north You went north This room has a table. Maybe a dinning room? Enter direction to move north west east south restart reset You went back to the start! This room is the entrance. Enter direction to move north west east south restart north You went north This room has a table. Maybe a dinning room? Enter direction to move north west east south restart west Direction invalid, try again. This room has a table. Maybe a dinning room? Enter direction to move north west east south restart east You went east You found the exit!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started