0

我创建了一个简单的益智游戏并将其上传到 kongregate,现在我想使用他们的 API 将高分(最少的移动量 = 更好)上传到它。为了确保没有人可以欺骗系统(在拼图完成之前提交分数),我需要确保拼图中没有一块是黑色的。拼图的所有部分都是影片剪辑,并且位于一个称为按钮的数组中。

我目前有这个:

    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);
            }
        }
    }

但我认为它会在检查不是黑色的电影剪辑后立即提交分数,并且会忽略其余部分。

4

1 回答 1

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
    }
}

希望一切都清楚。

祝你好运!

于 2016-01-16T20:02:30.973 回答