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 dict:Dictionary = 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")
}
}
[AS3] when I click my circles it doesn't match the randomly generated pattern.
Wednesday, June 27, 2012
[Action Script] [AS3] when I click my circles it doesn't match the randomly generated pattern. June,2012
Posted by Bimo Hery Prabowo at 3:13 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment