lundi 9 janvier 2017

How to make if clicked wrong buttons

I made a game remember for the first fishes.I found a code like this.I also have wrong buttons.Wrong buttons list

pinkButton.addEventListener(MouseEvent.CLICK, pinkClick);
whiteButton.addEventListener(MouseEvent.CLICK, whiteClick);
greyButton.addEventListener(MouseEvent.CLICK, greyClick);

And I use this code

import flash.events.MouseEvent;
var checkString:String = "";
 
//Create event listeners and their functions.
YellowButton.addEventListener(MouseEvent.CLICK, yellowClick);
RedButton.addEventListener(MouseEvent.CLICK, redClick);
BlueButton.addEventListener(MouseEvent.CLICK, blueClick);



/*True choices*/ 
function yellowClick(evt:Event):void
{
//In each event listener function, add a letter or 
//string to the checkString variable.
checkString += "y";
//Then, see if the string matches or not.
check();
}
function redClick(evt:Event):void
{
checkString += "r";
check();
}
function blueClick(evt:Event):void
{
checkString += "b";
check();
}
/*True choices*/
 
//If the proper sequence is red, yellow, blue, the string would read "ryb".
function check():void
{
if(checkString == "ryb")
{
 //Clear the checkString for convenience before going on.
  clearString();
  //CODE TO GO TO NEW FRAME
  gotoAndStop(3);
}
else
{
 //Make sure the string is at least 3 characters long.
 if(checkString.length >= 3)
{
clearString();
gotoAndStop(1);
    }   
  }
}
function clearString():void
{
//You will want to have a function for clearing the string.
//This is especially useful if you have a button for "start over."
checkString = "";
}

 

if I click yellow,red,blue it's work.it's ok.How I can make wrong choices ? Am I have to write a code for all possibilities ? Player have 1 chances.For example if player clicked 2 false and 1 true button,or 2 true and 1 false,this is mean is wrong.

Aucun commentaire:

Enregistrer un commentaire