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 に答える