Frame 1
function createGrid() {
currentCell = 0;
arrayOfCells = [];
i = 0;
while (i < _root.wide) {
thisRow = [];
j = 0;
while (j < _root.high) {
newCell = attachMovie("cell", "cell" + currentCell, this.getNextHighestDepth());
newCell._x = j * 25;
newCell._y = i * 25;
newCell.carved = false;
currentCell++;
thisRow.push(newCell);
j++;
}
arrayOfCells.push(thisRow);
i++;
}
}
function carveMaze() {
row = 15;
item = 21;
stack = [];
while (true) {
arrayOfCells[row][item].carved = true;
choices = [];
if (arrayOfCells[row][item + 1].carved == false) {
choices.push("EAST");
}
if (arrayOfCells[row][item - 1].carved == false) {
choices.push("WEST");
}
if (arrayOfCells[row + 1][item].carved == false) {
choices.push("SOUTH");
}
if (arrayOfCells[row - 1][item].carved == false) {
choices.push("NORTH");
}
if (choices.length == 0) {
if (stack.length == 0) {
return;
}
row = stack[stack.length - 1][0];
item = stack[stack.length - 1][1];
stack.pop();
} else {
if (choices.length >= 2) {
stack.push([row, item]);
}
choice = choices[random(choices.length)];
if (choice == "NORTH") {
arrayOfCells[row][item].north.gotoAndStop(2);
arrayOfCells[row - 1][item].south.gotoAndStop(2);
arrayOfCells[row - 1][item].carved = true;
row--;
}
if (choice == "EAST") {
arrayOfCells[row][item].east.gotoAndStop(2);
arrayOfCells[row][item + 1].west.gotoAndStop(2);
arrayOfCells[row][item + 1].carved = true;
item++;
}
if (choice == "SOUTH") {
arrayOfCells[row][item].south.gotoAndStop(2);
arrayOfCells[row + 1][item].north.gotoAndStop(2);
arrayOfCells[row + 1][item].carved = true;
row++;
}
if (choice == "WEST") {
arrayOfCells[row][item].west.gotoAndStop(2);
arrayOfCells[row][item - 1].east.gotoAndStop(2);
arrayOfCells[row][item - 1].carved = true;
item--;
}
}
}
}
wide = 22;
high = 22;
createGrid();
carveMaze();
stop();
Symbol 2 MovieClip Frame 1
stop();
Symbol 2 MovieClip Frame 2
stop();
Symbol 4 MovieClip Frame 1
stop();
Symbol 4 MovieClip Frame 2
stop();
Symbol 6 MovieClip Frame 1
stop();
Symbol 6 MovieClip Frame 2
stop();
Symbol 8 MovieClip Frame 1
stop();
Symbol 8 MovieClip Frame 2
stop();