2016-01-16 37 views
0

我創建了一個簡單的益智遊戲,並將其上傳到kongregate,現在我想使用他們的API上傳高分(最少移動=更好)。爲了確保沒有人能夠欺騙系統(在拼圖完成前提交分數),我需要確保拼圖中沒有任何棋子是黑色的。所有難題都是動畫片段,並在一個名爲按鈕的數組內。AS3檢查陣列中的動畫片段是否都是相同的顏色

我目前得到這個:

public function SumbitScore(e:MouseEvent) 
    { 
     for (var v:int = 0; v < buttons.length; v++) 
     { 
      if (buttons[v].transform.colorTransform.color != 0x000000) 
      { 
       _root.kongregateScores.submit(1000); 
      } 
     } 
    } 

但我認爲,將盡快提交分數,因爲它會檢查一個影片剪輯不是黑色的,它會忽略其他。

回答

1

我想要走的路是跟蹤在for循環中是否找到'空按鈕'。在循環之後,如果沒有找到空的方塊,可以提交分數,或讓玩家在提交之前知道拼圖必須完成。

我已經添加下面的代碼一些意見:

// (I changed the function name 'SumbitScore' to 'SubmitScore') 
public function SubmitScore(e:MouseEvent) 
{ 
    // use a boolean variable to store whether or not an empty button was found. 
    var foundEmptyButton : Boolean = false; 
    for (var v:int = 0; v < buttons.length; v++) 
    { 
     // check whether the current button is black 
     if (buttons[v].transform.colorTransform.color == 0x000000) 
     { 
      // if the button is empty, the 'foundEmptyButton' variable is updated to true. 
      foundEmptyButton = true; 
      // break out of the for-loop as you probably don't need to check if there are any other buttons that are still empty. 
      break; 
     } 
    } 
    if(foundEmptyButton == false) 
    { 
     // send the score to the Kongregate API 
     _root.kongregateScores.submit(1000); 
    } 
    else 
    { 
     // I'd suggest to let the player know they should first complete the puzzle 
    } 
} 

另外,您可以讓玩家知道自己還有多少按鍵來完成:

public function SubmitScore(e:MouseEvent) 
{ 
    // use an int variable to keep track of how many empty buttons were found 
    var emptyButtons : uint = 0; 
    for (var v:int = 0; v < buttons.length; v++) 
    { 
     // check whether the current button is black 
     if (buttons[v].transform.colorTransform.color == 0x000000) 
     { 
      // if the button is empty increment the emptyButtons variable 
      emptyButtons++; 
      // and don't break out of your loop here as you'd want to keep counting 
     } 
    } 
    if(emptyButtons == 0) 
    { 
     // send the score to the Kongregate API 
     _root.kongregateScores.submit(1000); 
    } 
    else 
    { 
     // let the player know there are still 'emptyButtons' buttons to finish before he or she can submit the highscore 
    } 
} 

希望這一切都清楚了。

祝你好運!

相關問題