iPhone 中的多人游戏 - 概念、策略、设计?

发布于 2024-09-06 22:17:11 字数 1436 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人爱我别走 2024-09-13 22:17:11

游戏如何搜索其他在线用户并显示所有用户列表?

您需要一个服务器,以某种数据格式(可能是 XML 或 JSON)将在线玩家列表返回到您的 iPhone 客户端。

如何请求某人加入游戏,然后其他用户才能看到?

最简单的方法是想要加入游戏的人将该命令发送到服务器,服务器告诉其他人他们想要加入。等待回复。如果第二个玩家说“是”,则返回到转发给第一个玩家的服务器。

它基本上是一系列发送到服务器和从服务器发送的命令。这就是所有多人游戏的工作方式 - 例如,Quake 引擎发送非常紧凑的命令,对于“获取服务器上的所有玩家”之类的命令,只有 4 个字节。考虑到 iPhone 连接的不稳定,这将是一个很好的复制模型,因为 Quake 网络代码是为 56k 调制解调器设计的。

牌桌上的玩家之间的连接和会话如何进行? (套接字?)

连接可以是连续流(UDP 最好),也可以是来自客户端的轮询。您需要考虑对两者进行扩展,因为 100 人玩游戏可能会让您的服务器瘫痪。

如果一名玩家失去连接,会话将被终止。或者,由于它是回合制的,每个玩家可以简单地在在线时发送命令,而另一个客户端在在线时接收该命令 - 在此模型中不需要会话,并且命令存储在服务器上的数据存储中。

作为服务器和客户端的一部分,什么样的网络编程是必需的?

我将扩展这一点:

  • 深入了解字节和位操作,包括位移位
  • 创建和读取 UDP 数据包的知识
  • 用 C 语言进行网络编程(Objective-C 可以简化很多)
  • 服务器:在 Linux 上编写守护进程,或 Windows 上的服务来监听命令
  • 如果您不关心带宽和连接丢失,则了解 SOAP、XML 或 JSON

How the game will search for other online users and will display the list of all users ?

You'll need a server that returns a list of online players to your iPhone client is some kind of data format, maybe XML or JSON.

How one can request someone to join the game and then visible to other users ?

The easiest approach would be the person who wants to to join the game sends that command to the server, the server tells that other person they want to join. Wait for a response. If player two says "yes", returns to the server which forwards to the first player.

It's basically a series of commands sent to and from the server. This is how all multiplayer games work - for example the Quake engine sends very compact commands, as little as 4 bytes for things like "get me all players on a server". Given the flakeyness of the iPhone connection this would be a good model to copy, as the Quake networking code was designed for 56k modems.

How the connection and session will work between players of a table ? (Sockets ?)

The connection could either be a continuous stream (UDP would be best), or polling from the client. You'll need to consider scaling for both, as it's possible 100 people playing could bring your server to its knees.

The session will be dropped if one player loses their connection. Alternatively as it's turn based, each player can simply send a command when they're online and the other client picks this up when he's online - there's no need for session in this model, and the commands are stored on the server in a datastore.

What sort of network programming is necessary as part of the server and client ?

I'll broaden this out:

  • An in depth knowledge of byte and bit manipulation including bit shifting
  • A knowledge of creating and reading UDP packets
  • Network programming in C (Objective-C may simplify a lot of this)
  • The server: writing daemons on Linux, or services on Windows to listen for commands
  • A knowledge of SOAP, XML or JSON if you're not concerned with bandwidth and connection drops
但可醉心 2024-09-13 22:17:11

您可能需要一台服务器来存储游戏状态,因为您无法保证两个(所有?)玩家同时在线。该存储的内容之一是轮到谁了。

然后,当玩家打开手机或开始游戏时,他们会看到一条消息,提示轮到他们了。

您也可以使用此服务器来存储高分和表格。

One thing you might need is a server to store the game state as you can't guarantee that both (all?) players will be on-line at the same time. One of the things this would store would be whose turn it was.

Then when a player turns on his/her phone or starts the game they would see a message saying it's their turn.

You could use this server to store high scores and tables too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文