def addRoom(self, adjRoom, type, direction=NO_DIR): # print "Add Room Called" # assign the room new coords relative to the adjacent room gridCoord = [0, 0] # if the new room is to the west of adjRoom if direction == WEST: gridCoord[x] = adjRoom.gridCoord[x] - 1 gridCoord[y] = adjRoom.gridCoord[y] # if the new room is to the north of adjRoom elif direction == NORTH: gridCoord[x] = adjRoom.gridCoord[x] gridCoord[y] = adjRoom.gridCoord[y] - 1 # if the new room is to the east of adjRoom elif direction == EAST: gridCoord[x] = adjRoom.gridCoord[x] + 1 gridCoord[y] = adjRoom.gridCoord[y] # if the new room is to the south of adjRoom elif direction == SOUTH: gridCoord[x] = adjRoom.gridCoord[x] gridCoord[y] = adjRoom.gridCoord[y] + 1 alreadyExists = False for room in self.rooms: if room.gridCoord == gridCoord: alreadyExists = True if not alreadyExists: # make the room newRoom = Room(direction, type, [None, None, None, None], gridCoord) newRoom.doors[opposite(direction)] = Door(opposite(direction)) adjRoom.doors[direction] = Door(direction) # update pointers if direction != NO_DIR: adjRoom.adjRooms[direction] = newRoom newRoom.adjRooms[opposite(direction)] = adjRoom newRoom.roomId = len(Dungeon.floorKeys) room = r.randint(0, len(self.rooms) - 1) xPos = r.randint(Room.currentRoom.boundingBox[WEST] + Key.keyImg.width/2, Room.currentRoom.boundingBox[EAST] - Key.keyImg.width/2) yPos = r.randint(Room.currentRoom.boundingBox[NORTH] + Key.keyImg.width/2, Room.currentRoom.boundingBox[SOUTH] - Key.keyImg.width/2) newKey = Key(xPos, yPos, self.rooms[room]) newRoom.rightKey = newKey Dungeon.floorKeys.append(newKey) self.rooms.append(newRoom) self.linkRooms(newRoom) return True if not alreadyExists else False