AS3 检查数组中的动画片段是否都是相同的颜色
AS3 Check if movieclips inside array are all the same color
我已经创建了一个简单的益智游戏并将其上传到 kongregate,现在我想使用他们的 API 将高分(最少的移动 = 更好)上传到它。为了确保没有人可以欺骗系统(在拼图完成之前提交分数),我需要确保拼图中 none 的部分是黑色的。拼图的所有部分都是动画片段,位于一个名为按钮的数组中。
我目前得到了这个:
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);
}
}
}
但我认为一旦检查到不是黑色的影片片段就会提交乐谱,并且会忽略其余部分。
我认为要走的路是跟踪是否在您的 for-loop 中找到 'empty button'。循环结束后,如果没有找到空方块,您可以提交分数,或者让玩家知道必须在提交前完成拼图。
我在下面的代码中添加了一些注释:
// (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
}
}
希望一切顺利。
祝你好运!
我已经创建了一个简单的益智游戏并将其上传到 kongregate,现在我想使用他们的 API 将高分(最少的移动 = 更好)上传到它。为了确保没有人可以欺骗系统(在拼图完成之前提交分数),我需要确保拼图中 none 的部分是黑色的。拼图的所有部分都是动画片段,位于一个名为按钮的数组中。
我目前得到了这个:
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);
}
}
}
但我认为一旦检查到不是黑色的影片片段就会提交乐谱,并且会忽略其余部分。
我认为要走的路是跟踪是否在您的 for-loop 中找到 'empty button'。循环结束后,如果没有找到空方块,您可以提交分数,或者让玩家知道必须在提交前完成拼图。
我在下面的代码中添加了一些注释:
// (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
}
}
希望一切顺利。
祝你好运!