stop();
detonation_mc.removeMovieClip();//删除MC
n = 0;
elapsedTime="00:00:00"
correctlyFlagged = 0;
flaggedMines = 0;
presses = 0;
framerate = 12;//帧速率,控制时间
areaWidth = 20;//列数
areaHeight = 20;//行数
cellHeight = 15;//方块高度
cellWidth = 15;//方块宽度
totalMines = 1;//炸弹数
MineSetting = 0;
xOff = (550-areaWidth*cellWidth)/2;
yOff = (400-areaHeight*cellHeight)/2;
mineCellArray = new Array();
fieldArray = new Array(areaWidth);
_root.createEmptyMovieClip("field", 1);
field._x = field._y=0;
for (x=0; x<areaWidth; x++)
{
fieldArray[x] = new Array(areaHeight);
}
for (x=0; x<areaWidth; x++) {
for (y=0; y<areaHeight; y++) {
n++;
field.attachMovie("cell", "cell"+x+"_"+y, n+2);
cell_mc = field["cell"+x+"_"+y];
cell_mc._width = cell_mc._height=cellWidth;
cell_mc._x = xOff+cellWidth*x;
cell_mc._y = yOff+cellHeight*y;
fieldArray[x][y] = cell_mc;
cell_mc.status_txt._visible = false;
cell_mc.MineSetting = 0;
cell_mc.status_txt.text = cell_mc.MineSetting;
cell_mc.mine = false;
cell_mc.visited = false;
cell_mc.flagged = false;
}
}
for (x=0; x<areaWidth; x++) {
for (y=0; y<areaHeight; y++) {
cell = fieldArray[x][y];
if (y>0) {
cell.CellN = fieldArray[x][y-1];
}
if (y<areaHeight-1) {
cell.CellS = fieldArray[x][y+1];
}
if (x>0) {
cell.CellW = fieldArray[x-1][y];
}
if (x<areaWidth-1) {
cell.CellE = fieldArray[x+1][y];
}
if (x>0 && y>0) {
cell.CellNW = fieldArray[x-1][y-1];
}
if (x>0 && y<areaWidth-1) {
cell.CellSW = fieldArray[x-1][y+1];
}
if (x<areaWidth-1 && y>0) {
cell.CellNE = fieldArray[x+1][y-1];
}
if (x<areaWidth-1 && y<areaWidth-1) {
cell.CellSE = fieldArray[x+1][y+1];
}
}
}
DeactivateAdjacent = function (cell) {
cell.CellN.gotoAndStop(2);
cell.CellE.gotoAndStop(2);
cell.CellW.gotoAndStop(2);
cell.CellS.gotoAndStop(2);
cell.CellN.status_txt._visible = true;
cell.CellE.status_txt._visible = true;
cell.CellW.status_txt._visible = true;
cell.CellS.status_txt._visible = true;
cell.CellNE.gotoAndStop(2);
cell.CellSE.gotoAndStop(2);
cell.CellNW.gotoAndStop(2);
cell.CellSW.gotoAndStop(2);
cell.CellNE.status_txt._visible = true;
cell.CellSE.status_txt._visible = true;
cell.CellNW.status_txt._visible = true;
cell.CellSW.status_txt._visible = true;
};
//Set Mines
SetARandomMine = function (fieldWidth, fieldHeight) {
mineCell = fieldArray[Math.floor(Math.random()*fieldWidth)][Math.floor(Math.random()*fieldHeight)];
if (mineCell.mine == false) {
mineCell.status_txt.text = "X";
mineCell.status_txt.textColor = 0xFF0000;
mineCell.mine = true;
mineCellArray.push(mineCell);
} else {
SetARandomMine(fieldWidth, fieldHeight);
}
};
for (m=0; m<totalMines; m++) {
SetARandomMine(areaWidth, areaHeight);
}
for (s=0; s<=totalMines; s++) {
cell = mineCellArray[s];
cell.CellN.mineSetting++;
cell.CellS.mineSetting++;
cell.CellE.mineSetting++;
cell.CellW.mineSetting++;
cell.CellNE.mineSetting++;
cell.CellSE.mineSetting++;
cell.CellNW.mineSetting++;
cell.CellSW.mineSetting++;
}
//trace(totalmines+","+mineCellArray.length);
SetColor = function (cell, color1, color2, color3, color4, color5, color6, color7, color8) {
if (cell.mineSetting == 1) {
cell.status_txt.textColor = color1;
}
if (cell.mineSetting == 2) {
cell.status_txt.textColor = color2;
}
if (cell.mineSetting == 3) {
cell.status_txt.textColor = color3;
}
if (cell.mineSetting == 4) {
cell.status_txt.textColor = color4;
}
if (cell.mineSetting == 5) {
cell.status_txt.textColor = color5;
}
if (cell.mineSetting == 6) {
cell.status_txt.textColor = color6;
}
if (cell.mineSetting == 7) {
cell.status_txt.textColor = color7;
}
if (cell.mineSetting == 8) {
cell.status_txt.textColor = color8;
}
};
for (x=0; x<areaWidth; x++) {
for (y=0; y<areaHeight; y++) {
cell = fieldArray[x][y];
if (cell.mine == false) {
cell.status_txt.text = cell.MineSetting;
setColor(cell, 0x6B9821, 0xAEAE00, 0xDFAB0F, 0xEE600B, 0xE43434, 0xEA75B9, 0x9A1FC5, 0x653F65);
if (cell.MineSetting == 0) {
cell.status_txt.text = "";
}
}
}
}
FindAdjacentZeros = function (startCell) {
success = false;
if (startCell.CellN.mineSetting == 0 && startCell.CellN != undefined) {
startCell.visited = true;
startCell.CellN.gotoAndStop(2);
startCell.CellN.status_txt.text = "";
success = true;
nextCell = startCell.CellN;
DeactivateAdjacent(nextCell);
if (nextCell.visited == false) {
nextCells.push(nextCell);
}
}
if (startCell.CellS.mineSetting == 0 && startCell.CellS != undefined) {
startCell.visited = true;
success = true;
startCell.CellS.gotoAndStop(2);
startCell.CellS.status_txt.text = "";
nextCell = startCell.CellS;
DeactivateAdjacent(nextCell);
if (nextCell.visited == false) {
nextCells.push(nextCell);
}
}
if (startCell.CellE.mineSetting == 0 && startCell.CellE != undefined) {
startCell.visited = true;
success = true;
startCell.CellE.gotoAndStop(2);
startCell.CellE.status_txt.text = "";
nextCell = startCell.CellE;
DeactivateAdjacent(nextCell);
if (nextCell.visited == false) {
nextCells.push(nextCell);
}
}
if (startCell.CellW.mineSetting == 0 && startCell.CellW != undefined) {
success = true;
startCell.visited = true;
startCell.CellW.gotoAndStop(2);
startCell.CellW.status_txt.text = "";
nextCell = startCell.CellW;
DeactivateAdjacent(nextCell);
if (nextCell.visited == false) {
nextCells.push(nextCell);
}
}
};
frame = 0;
seconds = 0;
minutes = 0;
hours = 0;
timer = false;
_root.onEnterFrame = function() {
if (timer) {
frame++;
if (frame>=framerate) {
frame = 0;
seconds++;
}
if (seconds>60) {
seconds = 0;
minutes++;
}
if (minutes>60) {
minutes = 0;
hours++;
}
if (seconds<10) {
var seconds = "0"+seconds;
}
if (minutes<10) {
var minutes = "0"+minutes;
}
if (hours<10) {
var hours = "0"+hours;
}
elapsedTime = hours+":"+minutes+":"+seconds;
}
if (correctlyFlagged == totalMines && flaggedMines == totalMines) {
completion();
}
};
detonation = function () {
_root.attachMovie("detonation_mc", "detonation_mc", 2);
detonation_mc._x = 275;
detonation_mc._y = 200;
detonation_mc.boxtext_txt.text = "boom!";
if (elapsedTime == undefined)
{
elapsedTime = "one click";
}
detonation_mc.boxtext_txt.text += "\n "+elapsedTime;
timer = false;
for (x=0; x<areaWidth; x++) {
for (y=0; y<areaHeight; y++) {
cell = fieldArray[x][y];
cell.gotoAndStop(2);
cell.status_txt._visible = true;
}
}
};
completion = function () {
_root.attachMovie("detonation_mc", "detonation_mc", 2);
detonation_mc._x = 275;
detonation_mc._y = 200;
detonation_mc.boxtext_txt.text = "wim! \n ";
detonation_mc.boxtext_txt.text += "\n"+elapsedTime;
timer=false;
for (x=0; x<areaWidth; x++) {
for (y=0; y<areaHeight; y++) {
cell = fieldArray[x][y];
cell.gotoAndStop(2);
cell.status_txt._visible = true;
}
}
};
MinePress = function (mc) {
if (mc.flagged == false) {
presses++;
if (presses>0) {
timer = true;
}
mc.gotoAndStop(2);
mc.status_txt._visible = true;
nextCells = new Array();
if (mc.mine == true) {
detonation();
}
if (mc.mineSetting == 0) {
FindAdjacentZeros(mc);
while (nextCells.length>1) {
nextCell2 = nextCells.pop();
FindAdjacentZeros(nextCell2);
}
}
}
};
FlagPress = function (mc) {
if (mc.flag._visible == false) {
flaggedMines++;
mc.flag._visible = true;
mc.flagged = true;
if (mc.mine == true) {
correctlyFlagged++;
}
} else {
flaggedMines--;
mc.flag._visible = false;
mc.flagged = false;
if (mc.mine == true) {
correctlyFlagged--;
}
}
};
detonation_mc.removeMovieClip();//删除MC
n = 0;
elapsedTime="00:00:00"
correctlyFlagged = 0;
flaggedMines = 0;
presses = 0;
framerate = 12;//帧速率,控制时间
areaWidth = 20;//列数
areaHeight = 20;//行数
cellHeight = 15;//方块高度
cellWidth = 15;//方块宽度
totalMines = 1;//炸弹数
MineSetting = 0;
xOff = (550-areaWidth*cellWidth)/2;
yOff = (400-areaHeight*cellHeight)/2;
mineCellArray = new Array();
fieldArray = new Array(areaWidth);
_root.createEmptyMovieClip("field", 1);
field._x = field._y=0;
for (x=0; x<areaWidth; x++)
{
fieldArray[x] = new Array(areaHeight);
}
for (x=0; x<areaWidth; x++) {
for (y=0; y<areaHeight; y++) {
n++;
field.attachMovie("cell", "cell"+x+"_"+y, n+2);
cell_mc = field["cell"+x+"_"+y];
cell_mc._width = cell_mc._height=cellWidth;
cell_mc._x = xOff+cellWidth*x;
cell_mc._y = yOff+cellHeight*y;
fieldArray[x][y] = cell_mc;
cell_mc.status_txt._visible = false;
cell_mc.MineSetting = 0;
cell_mc.status_txt.text = cell_mc.MineSetting;
cell_mc.mine = false;
cell_mc.visited = false;
cell_mc.flagged = false;
}
}
for (x=0; x<areaWidth; x++) {
for (y=0; y<areaHeight; y++) {
cell = fieldArray[x][y];
if (y>0) {
cell.CellN = fieldArray[x][y-1];
}
if (y<areaHeight-1) {
cell.CellS = fieldArray[x][y+1];
}
if (x>0) {
cell.CellW = fieldArray[x-1][y];
}
if (x<areaWidth-1) {
cell.CellE = fieldArray[x+1][y];
}
if (x>0 && y>0) {
cell.CellNW = fieldArray[x-1][y-1];
}
if (x>0 && y<areaWidth-1) {
cell.CellSW = fieldArray[x-1][y+1];
}
if (x<areaWidth-1 && y>0) {
cell.CellNE = fieldArray[x+1][y-1];
}
if (x<areaWidth-1 && y<areaWidth-1) {
cell.CellSE = fieldArray[x+1][y+1];
}
}
}
DeactivateAdjacent = function (cell) {
cell.CellN.gotoAndStop(2);
cell.CellE.gotoAndStop(2);
cell.CellW.gotoAndStop(2);
cell.CellS.gotoAndStop(2);
cell.CellN.status_txt._visible = true;
cell.CellE.status_txt._visible = true;
cell.CellW.status_txt._visible = true;
cell.CellS.status_txt._visible = true;
cell.CellNE.gotoAndStop(2);
cell.CellSE.gotoAndStop(2);
cell.CellNW.gotoAndStop(2);
cell.CellSW.gotoAndStop(2);
cell.CellNE.status_txt._visible = true;
cell.CellSE.status_txt._visible = true;
cell.CellNW.status_txt._visible = true;
cell.CellSW.status_txt._visible = true;
};
//Set Mines
SetARandomMine = function (fieldWidth, fieldHeight) {
mineCell = fieldArray[Math.floor(Math.random()*fieldWidth)][Math.floor(Math.random()*fieldHeight)];
if (mineCell.mine == false) {
mineCell.status_txt.text = "X";
mineCell.status_txt.textColor = 0xFF0000;
mineCell.mine = true;
mineCellArray.push(mineCell);
} else {
SetARandomMine(fieldWidth, fieldHeight);
}
};
for (m=0; m<totalMines; m++) {
SetARandomMine(areaWidth, areaHeight);
}
for (s=0; s<=totalMines; s++) {
cell = mineCellArray[s];
cell.CellN.mineSetting++;
cell.CellS.mineSetting++;
cell.CellE.mineSetting++;
cell.CellW.mineSetting++;
cell.CellNE.mineSetting++;
cell.CellSE.mineSetting++;
cell.CellNW.mineSetting++;
cell.CellSW.mineSetting++;
}
//trace(totalmines+","+mineCellArray.length);
SetColor = function (cell, color1, color2, color3, color4, color5, color6, color7, color8) {
if (cell.mineSetting == 1) {
cell.status_txt.textColor = color1;
}
if (cell.mineSetting == 2) {
cell.status_txt.textColor = color2;
}
if (cell.mineSetting == 3) {
cell.status_txt.textColor = color3;
}
if (cell.mineSetting == 4) {
cell.status_txt.textColor = color4;
}
if (cell.mineSetting == 5) {
cell.status_txt.textColor = color5;
}
if (cell.mineSetting == 6) {
cell.status_txt.textColor = color6;
}
if (cell.mineSetting == 7) {
cell.status_txt.textColor = color7;
}
if (cell.mineSetting == 8) {
cell.status_txt.textColor = color8;
}
};
for (x=0; x<areaWidth; x++) {
for (y=0; y<areaHeight; y++) {
cell = fieldArray[x][y];
if (cell.mine == false) {
cell.status_txt.text = cell.MineSetting;
setColor(cell, 0x6B9821, 0xAEAE00, 0xDFAB0F, 0xEE600B, 0xE43434, 0xEA75B9, 0x9A1FC5, 0x653F65);
if (cell.MineSetting == 0) {
cell.status_txt.text = "";
}
}
}
}
FindAdjacentZeros = function (startCell) {
success = false;
if (startCell.CellN.mineSetting == 0 && startCell.CellN != undefined) {
startCell.visited = true;
startCell.CellN.gotoAndStop(2);
startCell.CellN.status_txt.text = "";
success = true;
nextCell = startCell.CellN;
DeactivateAdjacent(nextCell);
if (nextCell.visited == false) {
nextCells.push(nextCell);
}
}
if (startCell.CellS.mineSetting == 0 && startCell.CellS != undefined) {
startCell.visited = true;
success = true;
startCell.CellS.gotoAndStop(2);
startCell.CellS.status_txt.text = "";
nextCell = startCell.CellS;
DeactivateAdjacent(nextCell);
if (nextCell.visited == false) {
nextCells.push(nextCell);
}
}
if (startCell.CellE.mineSetting == 0 && startCell.CellE != undefined) {
startCell.visited = true;
success = true;
startCell.CellE.gotoAndStop(2);
startCell.CellE.status_txt.text = "";
nextCell = startCell.CellE;
DeactivateAdjacent(nextCell);
if (nextCell.visited == false) {
nextCells.push(nextCell);
}
}
if (startCell.CellW.mineSetting == 0 && startCell.CellW != undefined) {
success = true;
startCell.visited = true;
startCell.CellW.gotoAndStop(2);
startCell.CellW.status_txt.text = "";
nextCell = startCell.CellW;
DeactivateAdjacent(nextCell);
if (nextCell.visited == false) {
nextCells.push(nextCell);
}
}
};
frame = 0;
seconds = 0;
minutes = 0;
hours = 0;
timer = false;
_root.onEnterFrame = function() {
if (timer) {
frame++;
if (frame>=framerate) {
frame = 0;
seconds++;
}
if (seconds>60) {
seconds = 0;
minutes++;
}
if (minutes>60) {
minutes = 0;
hours++;
}
if (seconds<10) {
var seconds = "0"+seconds;
}
if (minutes<10) {
var minutes = "0"+minutes;
}
if (hours<10) {
var hours = "0"+hours;
}
elapsedTime = hours+":"+minutes+":"+seconds;
}
if (correctlyFlagged == totalMines && flaggedMines == totalMines) {
completion();
}
};
detonation = function () {
_root.attachMovie("detonation_mc", "detonation_mc", 2);
detonation_mc._x = 275;
detonation_mc._y = 200;
detonation_mc.boxtext_txt.text = "boom!";
if (elapsedTime == undefined)
{
elapsedTime = "one click";
}
detonation_mc.boxtext_txt.text += "\n "+elapsedTime;
timer = false;
for (x=0; x<areaWidth; x++) {
for (y=0; y<areaHeight; y++) {
cell = fieldArray[x][y];
cell.gotoAndStop(2);
cell.status_txt._visible = true;
}
}
};
completion = function () {
_root.attachMovie("detonation_mc", "detonation_mc", 2);
detonation_mc._x = 275;
detonation_mc._y = 200;
detonation_mc.boxtext_txt.text = "wim! \n ";
detonation_mc.boxtext_txt.text += "\n"+elapsedTime;
timer=false;
for (x=0; x<areaWidth; x++) {
for (y=0; y<areaHeight; y++) {
cell = fieldArray[x][y];
cell.gotoAndStop(2);
cell.status_txt._visible = true;
}
}
};
MinePress = function (mc) {
if (mc.flagged == false) {
presses++;
if (presses>0) {
timer = true;
}
mc.gotoAndStop(2);
mc.status_txt._visible = true;
nextCells = new Array();
if (mc.mine == true) {
detonation();
}
if (mc.mineSetting == 0) {
FindAdjacentZeros(mc);
while (nextCells.length>1) {
nextCell2 = nextCells.pop();
FindAdjacentZeros(nextCell2);
}
}
}
};
FlagPress = function (mc) {
if (mc.flag._visible == false) {
flaggedMines++;
mc.flag._visible = true;
mc.flagged = true;
if (mc.mine == true) {
correctlyFlagged++;
}
} else {
flaggedMines--;
mc.flag._visible = false;
mc.flagged = false;
if (mc.mine == true) {
correctlyFlagged--;
}
}
};