Question
Python 3 Maze game Can someone debug my code and make it work as intended. A room will be the basic object for our maze
Python 3 Maze game
Can someone debug my code and make it work as intended.
A room will be the basic object for our maze game. A room can have 4 doors (pertaining to north, south, east, and west). Attached to each these directions we have either another room or None (we could also imagine that the None doors are just walls).
We want the player 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 have already been to.
class Room: #Constructor sets the description #All four doors should be set to None to start def Direction(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): return str("North: ", self.__north, "South: ", self.__south, "East: ", self.__east,"West : ", self.__west) def getNorth(self): return self.__north def getSouth(self): return self.__south def getEast(self): return self.__east def getWest(self): return self.__west #Mutators #Update the values def setDescription(self,d): self.__descr = d def setNorth(self,n): self.__north = n def setSouth(self,s): self.__south = s def setEast(self,e): self.__east = e def setWest(self,w): self.__west = w #Inputs: Pointer to start room and exit room #Sets current to be start room def Maze(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): return self.__current #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): if getNorth == None: return False elif getNorth != None: st = st + getNorth def moveSouth(self): if getSouth == None: return False elif getSouth != None: st = st + getSouth def moveEast(self): if getEast == None: return False elif getEast != None: st = st + getEast def getWest(self): if getEast == None: return False elif getNorth != None: st = st + getEast #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
my_rooms = [] my_rooms.append(Room.setDescription("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]) #Make a maze! #Set the start and exit rooms. my_maze = Maze(my_rooms[0],my_rooms[2])
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