Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 06-26-2012, 06:31 PM   #1
ibrahim011
Registered User
 
Join Date: Jun 2012
Posts: 4
Default [AS3] when I click my circles it doesn't match the randomly generated pattern.

i made a game in which you have nine circles and you have to click in the order randomly generated. when I click my circles it doesn't match the randomly generated pattern.

Heres my code:



import flash.events.MouseEvent;
import flash.events.Event;

var dictictionary = new Dictionary();
dict[obj_1] = "1";
dict[obj_2] = "2";
dict[obj_3] = "3";
dict[obj_4] = "4";
dict[obj_5] = "5";
dict[obj_6] = "6";
dict[obj_7] = "7";
dict[obj_8] = "8";
dict[obj_9] = "9";


var pattern:Array = [dict[obj_1], dict[obj_2], dict[obj_3], dict[obj_4], dict[obj_5], dict[obj_6], dict[obj_7], dict[obj_8], dict[obj_9]];

var shuffledPattern:Array = new Array(pattern.length);

var randomPos:int = 0;
for (var i:int = 0; i < shuffledPattern.length; i++)
{
randomPos = int(Math.random() * pattern.length);
shuffledPattern[i] = pattern[randomPos];
pattern.splice(randomPos, 1);
}

trace(shuffledPattern);

//ONCLICK fuction
// circles dim on click
//trace circle value

var clickpattern:Array = []


obj_1.addEventListener(MouseEvent.CLICK, onclick)

function onclick (m:MouseEvent){

obj_1.alpha = 0.5
clickpattern.push(dict[m.currentTarget])
trace(clickpattern);
}

obj_2.addEventListener(MouseEvent.CLICK, onclick2)

function onclick2 (m:MouseEvent){

obj_2.alpha = 0.5
clickpattern.push(dict[m.currentTarget])
trace(clickpattern);

}

obj_3.addEventListener(MouseEvent.CLICK, onclick3)

function onclick3 (m:MouseEvent){

obj_3.alpha = 0.5
clickpattern.push(dict[m.currentTarget])
trace(clickpattern);

}

obj_4.addEventListener(MouseEvent.CLICK, onclick4)

function onclick4 (m:MouseEvent){

obj_4.alpha = 0.5
clickpattern.push(dict[m.currentTarget])
trace(clickpattern);


}

obj_5.addEventListener(MouseEvent.CLICK, onclick5)

function onclick5 (m:MouseEvent){

obj_5.alpha = 0.5
clickpattern.push(dict[m.currentTarget])
trace(clickpattern);

}

obj_6.addEventListener(MouseEvent.CLICK, onclick6)

function onclick6 (m:MouseEvent){

obj_6.alpha = 0.5
clickpattern.push(dict[m.currentTarget])
trace(clickpattern);

}

obj_7.addEventListener(MouseEvent.CLICK, onclick7)

function onclick7 (m:MouseEvent){

obj_7.alpha = 0.5
clickpattern.push(dict[m.currentTarget])
trace(clickpattern);
}


obj_8.addEventListener(MouseEvent.CLICK, onclick8)

function onclick8 (m:MouseEvent){

obj_8.alpha = 0.5
clickpattern.push(dict[m.currentTarget])
trace(clickpattern);

}

obj_9.addEventListener(MouseEvent.CLICK, onclick9)

function onclick9 (m:MouseEvent){

obj_9.alpha = 0.5
clickpattern.push(dict[m.currentTarget])
trace(clickpattern);
}

done.addEventListener(MouseEvent.CLICK, doneclick)

function doneclick (m:MouseEvent){
if (shuffledPattern == clickpattern){

trace("you win");
}
else{

trace("you lose")
}

}
ibrahim011 is offline   Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:17 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.