var places = new Array();
places[0] = new Array(true, true, false, false, false);
places[1] = new Array(false, false, false, true, true);
places[2] = new Array(false, true, true, true, false);
places[3] = new Array(true, true, false, false, false);
var resp = new Array();
var famt = 0;
var c = 0;
for (var y=0; y<places.length; y++) {
for (var x=0; x<places[y].length; x++) {
var clp = this.attachMovie("pad", "p" + c, c);
clp._x = x * clp._width;
clp._y = y * clp._height;
var cl = new Color(clp);
var d = (places[y][x])? 0x00FF00 : 0xFF0000;
cl.setRGB(d);
c ++;
}
}
button.onPress = function() {
doCheck(parseInt(etext.text, 10));
}
function doCheck(a) {
checkPlaces(a);
showPlaces();
}
function showPlaces() {
for (var y=0; y<resp.length; y++) {
for (var x=0; x<resp[y].length; x++) {
var clp = this.attachMovie("pad", "p" + c, c);
clp._x = x * clp._width;
clp._y = y * clp._height + 100;
var cl = new Color(clp);
var d = (resp[y][x])? 0x00FF00 : 0xFF0000;
cl.setRGB(d);
c ++;
}
}
}
function clearResp() {
resp = new Array();
for (var y=0; y<places.length; y++) {
resp[y] = new Array(places[y].length);
for (var x=0; x<places[y].length; x++) {
resp[y][x] = false;
//trace(resp[y][x]);
}
}
famt = 0;
}
function countResp() {
var c = 0;
for (var y=0; y<places.length; y++) {
for (var x=0; x<places[y].length; x++) {
if (resp[y][x] == true) c ++;
}
}
return c;
}
function checkPlaces(amt) {
for (var i=1; i<=3; i++) {
for (var y=0; y<places.length; y++) {
for (var x=0; x<places[0].length; x++) {
clearResp();
resp = flood(places, i, x, y, resp, amt);
if (countResp() >= amt) return true;
}
}
}
}
function flood(matrix, fmode, x, y, rmtx, amt) {
if (famt >= amt) return rmtx;
if (matrix[y][x] == true && rmtx[y][x] != true) {
rmtx[y][x] = true;
famt ++;
switch(fmode) {
case 1:
rmtx = flood(matrix, fmode, x - 1, y, rmtx, amt);
rmtx = flood(matrix, fmode, x + 1, y, rmtx, amt);
break;
case 2:
rmtx = flood(matrix, fmode, x - 1, y, rmtx, amt);
rmtx = flood(matrix, fmode, x + 1, y, rmtx, amt);
rmtx = flood(matrix, fmode, x, y - 1, rmtx, amt);
rmtx = flood(matrix, fmode, x, y + 1, rmtx, amt);
break;
case 3:
rmtx = flood(matrix, fmode, x - 1, y, rmtx, amt);
rmtx = flood(matrix, fmode, x + 1, y, rmtx, amt);
rmtx = flood(matrix, fmode, x, y - 1, rmtx, amt);
rmtx = flood(matrix, fmode, x, y + 1, rmtx, amt);
rmtx = flood(matrix, fmode, x - 1, y - 1, rmtx, amt);
rmtx = flood(matrix, fmode, x + 1, y - 1, rmtx, amt);
rmtx = flood(matrix, fmode, x - 1, y + 1, rmtx, amt);
rmtx = flood(matrix, fmode, x + 1, y + 1, rmtx, amt);
break;
}
}
return rmtx;
}