2017-04-05 1 views
-3

あなたが最初に持っていたas3でメモリゲームを作る方法を知りたがっています。as3メモリーでゲームを開発していますか?

1 - ゲームが実行されるたびにカードはランダムです。

2 - カードが同じであり、消滅するかどうかを確認するための少なくとも1つの条件があります。

、3-カードが等しくない場合にだけ、フレームにカード

が含まれているムービークリップの通常

4 - すべてへの復帰が

を理解いただきありがとうございます私はこのコードを持っていますfar:

import flash.events.MouseEvent;

//variáveis relativo ao score, pattern and so on 
var pattern = new Array(); 
var buttons = new Array(); 
buttons.push(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); 
var position = 0; 

//Dizer aos botões que esperam ser clicados pelo rato 
a.addEventListener(MouseEvent.CLICK, Clicked); 
b.addEventListener(MouseEvent.CLICK, Clicked); 
c.addEventListener(MouseEvent.CLICK, Clicked); 
d.addEventListener(MouseEvent.CLICK, Clicked); 
e.addEventListener(MouseEvent.CLICK, Clicked); 
f.addEventListener(MouseEvent.CLICK, Clicked); 
g.addEventListener(MouseEvent.CLICK, Clicked); 
h.addEventListener(MouseEvent.CLICK, Clicked); 
i.addEventListener(MouseEvent.CLICK, Clicked); 
j.addEventListener(MouseEvent.CLICK, Clicked); 
k.addEventListener(MouseEvent.CLICK, Clicked); 
l.addEventListener(MouseEvent.CLICK, Clicked); 
m.addEventListener(MouseEvent.CLICK, Clicked); 
n.addEventListener(MouseEvent.CLICK, Clicked); 
o.addEventListener(MouseEvent.CLICK, Clicked); 
p.addEventListener(MouseEvent.CLICK, Clicked); 

function Clicked(clickInfo:MouseEvent){ 
trace("Clique"); 
switch(clickInfo.target){ 
case a: 
clickInfo.target.gotoAndStop(2); 
break; 
case b: 
clickInfo.target.gotoAndStop(3); 
} 
} 

そして、私はあなたが私が

答えて

2

ステップ1を決めた4つのオブジェクトのいずれか表示させる文字のいずれかをクリックします:あなたはフリップを処理し、画像を表示カードのクラスを作成する必要がありますがその割り当てられた値に適している。基本的に、以下の方法:

Card.assign(type:int); // To assign a value and tell the card which face to show. 
Card.unflip(); // Show back and enable mouse. 
Card.flip(); // Show face and disable mouse. 

ステップ2:カードのランダムな対に同じ値を割り当てます。

// Must contain 16 cards. 
var Cards:Vector.<Card> = new Vector.<Card>; 
Cards.push(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); 

// Lets make a copy. 
var aCopy:Vector.<Cards> = Cards.slice(); 

// Lets take 8 random pairs and assign them values. 
for (var i:int = 1, i <= 8; i++) 
{ 
    var aCard:Card = extractRandom(aCopy); 
    var bCard:Card = extractRandom(aCopy); 

    aCard.assign(i); 
    bCard.assign(i); 
} 

function extractRandom(list:Vector.<Cards>):Card 
{ 
    // Obtain random card. 
    var anIndex:int = list.length * Math.random(); 
    var result:Card = list[anIndex]; 

    // Remove it from list. 
    // That is why we are working with the copy of the original array. 
    list.splice(anIndex, 1); 

    return result; 
} 

ステップ3:コアループ。

for each (var aCard:Card in Cards) 
{ 
    aCard.addEventListener(MouseEvent.CLICK, onClick); 
} 

// To store selected cards. 
var firstCard:Card; 
var secondCard:Card; 

// To keep track of user's progress. 
var totalPairs:int = 8; 
var matchedPairs:int = 0; 

function onClick(e:Event):void 
{ 
    // If secondCard is set then user is watching 2 
    // wrong cards at he moment. Must ignore clicks. 
    if (secondCard) return; 

    // Get reference to the clicked card. 
    var aCard:Cards = e.currentTarget as Card; 

    if (firstCard) 
    { 
     // Save the second selected card reference. 
     secondCard = aCard; 
     secondCard.flip(); 

     if (firstCard.type == secondCard.type) 
     { 
      // If cards are matched then just leave them open immediately. 
      firstCard = null; 
      secondCard = null; 

      matchedPairs++; 

      if (matchedPairs == totalPairs) 
      { 
       // Win. 
      } 
     } 
     else 
     { 
      // Otherwise let user watch the for a while and then close. 
      setTimeout(unMatch, 1000); 
     } 
    } 
    else 
    { 
     // Save the first selected card reference. 
     firstCard = aCard; 
     firstCard.flip(); 
    } 
} 

function unMatch():void 
{ 
    firstCard.unflip(); 
    secondCard.unflip(); 

    firstCard = null; 
    secondCard = null; 
} 
+0

ありがとう –