PHP 黑杰克游戏;更新显示
我在 stackOverflow 上的第一个问题!在这里阅读了大量有用的花絮,但无法找到以下问题的有用答案。
我用 PHP 编写了一个二十一点游戏,作为 OO PHP 的学习经验。我有一个主要对象,其中包含所有卡牌和游戏状态的详细信息,我将其序列化并将其保存到文件中,但是当多个人同时玩游戏时,这会导致冲突。我已经研究了会话并将这些数据保存在那里,但想知道我是否需要生成特殊的会话 ID 等。我该怎么做
此外,对于我没有考虑过的这个问题可能有一个很好的解决方案。提前致谢。
my first question on stackOverflow! Have read tons of useful tidbits on here, but haven't been able to find a useful answer to the following question.
I've written a blackjack game in PHP as a learning experience in OO PHP. I have one main object which contains the details of all the cards and the game state, I serialize this and save it to a file however this will cause conflicts when more than one person is playing at the same time. I've looked into sessions and saving this data there, but wonder if I need to generate special session id's etc. How do I
Also, there might be a good solution to this problem I haven't considered. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我要做的就是使用数据库来解决这个问题。您不应该使用会话来保存游戏状态,因为它将要求游戏的所有玩家都具有相同的数据,因此,您需要复制每个玩家的数据并将其保存在其他玩家的会话中。
当您尝试访问数据库中的数据时,使用会话进行身份验证并了解谁是谁
What I'd do is use a database for this matter. You shouldn't use sessions to save the game state since it will require all players of the game to have the same data, thus, you will need to duplicate every player's data and save it in the other player's session.
Use sessions to authenticate and know who is who when you're trying to access data from your database