我创建了一个带有 1v1 配对系统的网站。
以下是它的工作原理:
如果我单击查找对手,它会在数据库中更改 matchmaking=1。
但是有一个问题,如果用户在网站真正找到对手之前点击“查找对手”按钮然后退出,则对手匹配不会重置为 0。因此,如果另一个用户来了,他可能会与一个不活跃的用户配对。
所以我认为(但我不确定)我需要一个系统来检测用户何时单击返回按钮。目标是获得一个无故障配对两个和两个用户的防故障系统。任何帮助表示赞赏。
索引.html
<div class="menuItem" onclick="location.href='matchmaker.php';">find an opponent</div>
matchmaker.php(简而言之)
connect_to_server();
set_matchmaking_to_one();
$opponent = NULL;
while ($opponent == NULL) {
$player = look_for_player_with_matchmaking_on();
$opponent = mysqli_fetch_array($player)[0]; //this gets the id if exists
}
echo "your opponent: " . $opponent;
// after while loop an opponent should be found.