这是我想做的
到目前为止,我想在执行操作之前执行一个循环或类似的操作,我正在这样做
//check if it's multiplayer mode
if ([PlayerInfo instance].playingMultiplayer == YES)
{
//no cards has been played
//the while and NSRunLoop combination seems harsh
while ([PlayerInfo instance].cardsPlayed == NULL)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
//after the "loop thing" done, execute this method
//take out cards with the broadcasted cardsPlayed, it's event based
[self takeOutCards:[PlayerInfo instance].cardsPlayed];
}
//single player, don't bother this
else
{
//AI logic, select possible best cards
NSArray * bestCards = [playerLogic selectBestMove];
[self takeOutCards:bestCards];
}
这看起来是一种不好的做法。
顺便说一下,[PlayerInfo instance].cardsPlayed 是一个从服务器广播的变量,会经常更改。基于用户交互的更改,而另一个用户将等待将播放哪些牌。
简而言之,在等待广播变量到来时我应该怎么做?有什么建议吗?谢谢