我有一个扑克游戏,其中2到5个玩家在按下开始按钮之前加入游戏。他们作为包含用户名和用户名的对象添加到玩家阵列数组中。需要通过一个动态大小的数组循环php
我需要填充我的播放器对象currentUser然后点击一个按钮(呼叫/升/倍)移动到阵列中的下给游戏活动座椅的错觉座位
当启动按钮被点击我将当前用户设置为数组中的第一个元素。
$thisPokergame->State['CurrentUser'] = RESET($thisPokergame->State['Players']);
然后即时如果尝试这种
if($thisPokergame->State['CurrentUser'] == end($thisPokergame->State['Players']))
{
$thisPokergame->State['CurrentUser'] = reset($thisPokergame->State['Players']);
}
else{
$thisPokergame->State['CurrentUser'] = next($thisPokergame->State['Players']);;
}
作品本身e.g如果阵列中的最后一名选手将它设置当前用户为第一,所以做了其他内声明。
当我把它们放在一起我得到currentuser为false,我不能看到原因。任何人有解决方案或更好的方法来做到这一点?
为什么你不使用变量来跟踪当前玩家的位置。你从'$ activePosition = 0'开始为player1,然后使用'$ currentUser = $ thisPokergame-> State ['Players] [$ activePosition];'然后当玩家改变你增加计数器'$ counter = ++ $ counter/5;'如果你有5个玩家。或者,你的“国家”中的位置很重要? – olibiaz