0

我创建了一个带有 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.
4

1 回答 1

0
  1. 如果你有一个按钮/链接来退出quque,你可以从匹配中删除用户,如果他点击它。

或者

  1. 在你真正开始比赛之前,你可以创建一个对话框来确认用户仍然在那里。如果用户在时间 x 之后没有确认,则取消该匹配。您可以为此使用一些 ajax 代码。
于 2020-03-14T23:08:20.253 回答