我创建了一个简单的益智游戏并将其上传到kongregate,现在我想使用他们的API上传高分(最少的动作=更好)。为了确保没有人可以欺骗系统(在拼图完成之前提交分数)我需要确保拼图中没有任何部分是黑色的。拼图的所有部分都是动画片段,位于一个名为buttons的数组中。
我目前得到了这个:
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);
}
}
}
但我认为只要它检查一个非黑色的动画片段并且忽略其余部分就会提交分数。
答案 0 :(得分: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
}
}
希望一切都清楚。
祝你好运!