Posted 05 July 2012 - 02:50 PM
I have this code from :
This function gives problems as it features repetitions.
This is normally not a problem.. Unless you want a big maze.
If anyone is able to turn this to NOT use repetition.
I would be very very grateful.
I've tried to do this a few times but rage quitted..
If you would like to know how this works
Its kind of simple.
Basically its function inception..
This function gives problems as it features repetitions.
This is normally not a problem.. Unless you want a big maze.
function Maze:_process_neighbor_cells(x, y)
self.cells[y][x].is_visited = true
local neighbor_cells = self:_shuffle(self:_get_neighbor_cells(x, y))
for index, neighbor_cell in ipairs(neighbor_cells) do
if self.cells[neighbor_cell.y][neighbor_cell.x].is_visited == false then
if neighbor_cell.x > x then -- open wall with right neighbor
self.cells[y][x].right_wall = false
self.cells[neighbor_cell.y][neighbor_cell.x].left_wall = false
elseif neighbor_cell.x < x then -- open wall with left neighbor
self.cells[y][x].left_wall = false
self.cells[neighbor_cell.y][neighbor_cell.x].right_wall = false
elseif neighbor_cell.y > y then -- open wall with bottom neighbor
self.cells[y][x].bottom_wall = false
self.cells[neighbor_cell.y][neighbor_cell.x].top_wall = false
elseif neighbor_cell.y < y then -- open wall with top neighbor
self.cells[y][x].top_wall = false
self.cells[neighbor_cell.y][neighbor_cell.x].bottom_wall = false
end
-- recursively process this cell
self:_process_neighbor_cells(neighbor_cell.x, neighbor_cell.y)
end
end
return
end
If anyone is able to turn this to NOT use repetition.
I would be very very grateful.
I've tried to do this a few times but rage quitted..
If you would like to know how this works
Its kind of simple.
Function is called on
Function checks all sides around the sides it was given
If sides matches sides then it does some stuff then calls on this function again
If not then it returns
Function ends
Basically its function inception..