AS3 Проверьте, имеют ли мувиклипы внутри массива одинаковый цвет
Я создал простую игру-головоломку и загрузил ее в 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);
}
}
}
но я думаю, что он отправит счет, как только проверит видеоклип, который не черный, и он проигнорирует все остальное.
1 ответ
Я думаю, что для этого нужно отслеживать, найдена ли в вашем цикле "пустая кнопка". После окончания цикла вы можете отправить счет, если пустые плитки не были найдены, или сообщить игроку, что головоломка должна быть завершена перед отправкой.
Я добавил несколько комментариев в коде ниже:
// (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
}
}
Надеюсь, все ясно.
Удачи!