最近我一直在ActionScript 3纸牌游戏项目中工作,并遇到事件处理程序的问题,我发现它有点复杂。我会试着解释一下:在ActionScript 3中返回事件的值
有不确定数量的玩家轮流玩牌。在他们这样做之后,他们将转弯权交给右边的球员。
function Round(table:Table, lead:Player)/*Table is the list of players.
Lead is the person that starts the round*/
{
private var query:int = 0;
private var roundEnd:Boolean = false;
private var currentplater:Player = lead;
while(roundEnd == false)
{
query = currentPlayer.hasTurn();/*I'll explain this one later. It's
the problematic one*/
//Game stuff happens.
currentPlayer = currentPlayer.nextPlayer;/*Once the turn is over,
it gets assigned to the next player*/
if(currentPlayer.nextPlayer == lead)
{
roundEnd = true;//Everyone has played
}
}
}
正如评论那里,复杂的是hasTurn
。该函数必须从Player类激活并触发玩家处理事件的权限并返回一个整数值。
public function hasTurn():int
{
for each(var cards:Card in hand)
{
cards.addEventListener(MouseEvent.CLICK, playCard);
}
}
而在这之后
public function playCard(theCard:Card)
{
for each(var cards:Card in hand)
{
cards.removeEventListener(MouseEvent.CLICK, playCard);
}
//More game stuff happens. Not currently relevant.
}
我在这里做的是允许在玩家手中的每一张牌要播放,然后采取这些权限离开时,其中一人,但我从来不回一个值为Round
,更重要的是,我不能让下一个玩家稍后玩。我在脑海中多次解决了这个问题,但似乎无法找到hasTurn
返回值或结束其执行的方式,因此Round
代码可以继续工作。我是以错误的方式处理这个问题的逻辑吗?
注:我不知道这个问题是非常明显的,因为它是。我尽了最大的努力来表达这样一个具体问题的性质,但告诉我是否需要编辑该帖子。谢谢 – Anthony
你在做什么纯粹是错误的 - 你不能使用游戏执行循环的其他循环(它不是JAVA) - 只是因为闪存循环停止执行/渲染所有内容,直到完成。它可能工作 - 循环 - 如果它是一个输入框架循环。 –
@ Lukasz'Severiaan'Grela有趣。我会研究一下。我可以使用什么路径来解决不涉及循环的问题? – Anthony