2017-01-09 1 views
0

私は最初の魚を覚えています。私はこのようなコードを見つけました。私も間違ったボタンがあります。ユーザーが間違ったボタンをクリックした場合、どのようにキャプチャできますか?

間違ったボタンのリスト:

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

そして、私はそれが動作、黄色、赤、青をクリックした場合、私は

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 = ""; 
} 

このコードを使用します。どうすれば間違った選択をすることができますか?私はすべての可能性のためにコードを書く必要がありますか?プレイヤーには1チャンスがある。たとえば、プレーヤーが2つの偽と1つの真のボタン、または2つの真と1つの偽をクリックした場合、これはプレーヤーに損失をもたらします。

答えて

1

値の配列を使用します。

:同様

var correctSequence:Array = ["r", "y", "b"]; 

は、あなたは、アレイに

var arrayPosition:int = 0; 

をトラバースを制御し、あなたが間違った推測があったかどうかのブール値を保持する変数が必要与えるインクリメント変数を持っています

var noneWrong:Boolean = true; 

次にあなたが

private function playerNextGuess(e:MouseEvent):void{ 
    if (e.target._color == correctSequence[arrayPosition] && noneWrong == true){ 
     arrayPosition++; 
     if (arrayPosition == 3){ 
      playerWin(); 
      arrayPosition = 0; 
     } 
    } else { 
     // put whatever logic you want for when the guess is wrong 
     noneWrong = false; 
     arrayPosition++; 
     if (arrayPosition == 3){ 
      playerLose(); 
      arrayPosition = 0; 
     } 
    } 
ような何かを行うことができます

これにより、結果(正誤)がプレーヤーに与えられる前に3つの推測が行われるようになります。しかし、それはプレイヤーに正しいと間違っていたことを伝えません。何も間違っていなければ、win関数が呼び出されます。いずれかが間違っていれば、失効関数が呼び出されます。それはあなたが望んだことですか?

うまくいけば、あなたが正しい方向に進むことを望みます。私が書いたものが豊富にはっきりしていないかどうかを教えてください。

+0

ありがとうdoc.iは動作していないのでそのコードを忘れています。新しいコードを使用しますが、問題があります。コードは です。 fish1.addEventListener(MouseEvent.CLICK、click1); fish2.addEventListener(MouseEvent.CLICK、click2); fish3.addEventListener(MouseEvent.CLICK、click3); fish4.addEventListener(MouseEvent.CLICK、click4); var PC:Boolean = false; function click1(m:MouseEvent){ PC = true; } function click2(m:MouseEvent){ PC = true; } function click3(m:MouseEvent){ PC = true; } function click4(m:MouseEvent){ if(PC){ PC = false; gotoAndPlay(1); } } – KucuKeko

+0

2ボタンの真をクリックした後に進む必要があります.2ボタンが真2ボタンが偽です。 – KucuKeko

+0

新しい質問がありますか?新しい投稿を作成する私はコメントのフォーマットされていないコードを読んでほしくないです –

関連する問題