forked from: forked from: forked from: forked from: lightsOut x Ver
I don't know what to say ....
The "lightsOut" rule was broken ....
/**
* Copyright dannnn ( http://wonderfl.net/user/dannnn )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/tw74
*/
// forked from dannnn's forked from: forked from: forked from: lightsOut x Ver
// forked from dannnn's forked from: forked from: lightsOut x Ver
// forked from dannnn's forked from: lightsOut x Ver
// forked from MINOsuke's lightsOut x Ver
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(backgroundColor="#ffffff",width="465",height="465",frameRate="30")]
public class Main extends Sprite
{
private var n:int = 3;
private var lis:Array;
private var sp:Vector.<Sprite>;
private var colorFace:uint = 0xFF1721;
private var colorFace2:uint = 0xFFFF21;
private var colorFace3:uint = 0x19FF21;
private var colorFace4:uint = 0x19FFFF;
private var colorFace5:uint = 0x1917FF;
private var colorFace6:uint = 0xFF19FF;
private var colorBack:uint = 0xffffff;
private var span:int = 10;
private var r:int = 20;
public function Main():void
{
if (stage)
init();
else
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// initialization
sp = new Vector.<Sprite>();
lis = new Array();
var xOffset:int = (stage.stageWidth - (n - 1) * (2 * r + span)) / 2;
var yOffset:int = (stage.stageHeight - (n - 1) * (2 * r + span)) / 2;
for (var j:int = 0; j < n; j++)
{
lis[j] = new Array();
for (var i:int = 0; i < n; i++)
{
var p:int = j * n + i;
sp[p] = new Sprite();
sp[p].graphics.clear();
sp[p].graphics.lineStyle(1, 0x000000, 0.7);
sp[p].graphics.beginFill(colorBack, 1);
sp[p].graphics.drawCircle(0, 0, r);
sp[p].graphics.endFill();
sp[p].x = xOffset + (2 * r + span) * i;
sp[p].y = xOffset + (2 * r + span) * j;
sp[p].name = "" + j + "_" + i;
sp[p].addEventListener(MouseEvent.CLICK, clicked);
sp[p].buttonMode = true;
this.addChild(sp[p]);
lis[j][i] = 0;
}
}
start();
}
private function start(e:Event = null):void
{
this.addEventListener(Event.ENTER_FRAME, onEnter);
}
private function onEnter(e:Event = null):void
{
for (var j:int = 0; j < n; j++)
{
for (var i:int = 0; i < n; i++)
{
var p:int = j * n + i;
sp[p].graphics.clear();
sp[p].graphics.lineStyle(1, 0x000000, 0.7);
if (lis[j][i] == 0)
{
sp[p].graphics.beginFill(colorBack, 1);
}
if(lis[j][i]%7 == 1)
{
sp[p].graphics.beginFill(colorFace, 1);
}
if(lis[j][i]%7 == 2){
sp[p].graphics.beginFill(colorFace2, 1);
}
if(lis[j][i]%7 == 3){
sp[p].graphics.beginFill(colorFace3, 1);
}
if (lis[j][i] % 7 == 4)
{
sp[p].graphics.beginFill(colorFace4, 1);
}
if (lis[j][i] % 7 == 5)
{
sp[p].graphics.beginFill(colorFace5, 1);
}
if (lis[j][i] % 7 == 6)
{
sp[p].graphics.beginFill(colorFace6, 1);
}
sp[p].graphics.drawCircle(0, 0, r);
sp[p].graphics.endFill();
}
}
}
private function clicked(e:MouseEvent = null):void
{
var index:Array = e.target.name.split("_");
var j:int = index[0];
var i:int = index[1];
var pj:int = index[0];
var pi1:int = index[1];
var pi2:int = index[1];
var x:int = 5;
lis[j][i] ^= x;
x++;
lis[j][i]++;
pj = j - 1;
pi1 = i - 1;
pi2 = i + 1;
while (pj >= 0)
{
if (pi1 >= 0)
{
lis[pj][pi1] ^= x;
}
if (pi2 < n)
{
lis[pj][pi2] ^= x;
}
pj--;
pi1--;
pi2++;
}
pj = j + 1;
pi1 = i - 1;
pi2 = i + 1;
while (pj < n)
{
if (pi1 >= 0)
{
lis[pj][pi1] ^= x;
}
if (pi2 < n)
{
lis[pj][pi2] ^= x;
}
pj++;
pi1--;
pi2++;
}
}
}
}