stop();
/*******************************************************************************/
/****************************MAIN GAME FUNCTIONS*********************************/
_global.nxtColor;
_global.ptsCount;
_global.speed = 2;
_global.setAllVisible = new Boolean(false);
_global.butt_enabler = new Boolean(true);
_global.gameInProgress = new Boolean();
_global.com_array = new Array(); //saves computers choice
_global.usr_array = new Array(); //saves players choice
/*************************/
function initGame() {
gameInProgress = true;
ptsCount = -1;
nxtColor = -1;
com_array = new Array();
usr_array = new Array();
setAllVisible = false;
/*****start game*****/
mainGame();
}
/*******************************************************************************/
function mainGame() {
butt_enabler = false; //disable buttons
/*computer choice:*/
var newColor = random(9);
var i = 0;
if (com_array.length>0) {
setAllVisible = false;
}
// avoid colour double choice
while (newColor == lastColor) {
newColor = random(8);
}
com_array.push(newColor);
function showComputerChoice() {
if (i<com_array.length) {
i++;
nxtColor = com_array[i-1];
} else {
clearInterval(count);
setAllVisible = true;
i = 0;
usr_array.splice(0);
lastColor = nxtColor;
//preventing colour 'afterburning'
delete nxtColor;
butt_enabler = true; //enable buttons again
}
}
var count = setInterval(showComputerChoice, 700-(speed*100));
}
/*******************************************************************************/
MovieClip.prototype.butt_action = function() {
if (butt_enabler) {
nextUsrChoice = this._name;
usr_array.push(nextUsrChoice);
ptsCount = ptsCount+usr_array.length;
if (usr_array[usr_array.length-1] != com_array[usr_array.length-1]) {
butt_enabler = false;
gameInProgress = false;
setAllVisible = false;
return;
}
if (usr_array.length == com_array.length) {
mainGame();
}
}
};
/*******************************************************************************/
MovieClip.prototype.butt_behave = function() {
if (this._alpha<=100) {
if (nxtColor == this._name || setAllVisible == true) {
this._alpha += 25;
}
}
if (this._alpha>=0) {
if (setAllVisible != true) {
if (nxtColor != this._name) {
this._alpha -= 25;
}
}
}
};
/*******************************************************************************/
/****************************CREATE PLAYGROUND***********************************/
_global.numbers = new Boolean(true);
_global.design = new Array("0xCC3300", "0x336666", "0x000099", "0xFFCC00", "0x996699", "0xFF9900", "0x993300", "0x3399FF", "0xFF6699");
function generatePlayground(design:Array, num:Boolean) {
//trace("generatePlayground called!");
_root.createEmptyMovieClip("playground", 10);
var x = 0;
var y = 0;
for (var i = 1; i<10; i++) {
var buttonName = i-1;
playground.createEmptyMovieClip(buttonName, i);
playground[""+buttonName]._name = buttonName;
playground[""+buttonName]._x = x;
x += 70;
playground[""+buttonName]._y = y;
if (i%3 == 0) {
y += 70;
x = 0;
}
drawRect(playground[""+buttonName], 50, design[i-1]);
playground[""+buttonName].onEnterFrame = butt_behave;
playground[""+buttonName].onRelease = butt_action;
}
}
function drawRect(mc:MovieClip, size:Number, color) {
mc.beginFill(color);
mc.lineTo(size, 0);
mc.lineTo(size, size);
mc.lineTo(0, size);
mc.lineTo(0, 0);
mc.endFill();
}
generatePlayground(design, true);
/*******************************************************************************/
/****************************CREATE STARTBUTTON*********************************/
_global.txtFormat = new TextFormat();
txtFormat.color = 0xff0000;
txtFormat.font = "verdana";
txtFormat.size = 10;
/*******************************************************************************/
function createStartButton() {
_root.createEmptyMovieClip("startButton", 11);
startButton._x = 200;
startButton._y = 0;
startButton.createTextField("label_txt",12,2,3,20,20);
startButton.label_txt.setNewTextFormat(txtFormat);
startButton.label_txt.text = "GO";
drawRect(startButton, 25, "0xCC3300");
startButton.onRelease = initGame;
}
createStartButton();