回合制棋盘游戏的网络通信
这是我的第一个问题,所以如果出现问题,请不要太严厉:)
我目前是一名计算机科学学生(来自德国,如果这个信息有任何用处的话;))我们有一个免费的可选择的编程作业,我们必须在 C++/CLI Windows 窗体应用程序中编写它。
我的团队、另外两个人和我决定选择棋盘游戏《Risk》的网络兼容端口。
我们将工作分为 3 个部分,即 UI、游戏逻辑和网络。现在我们必须让所有东西协同工作,最大的问号是,如何让客户端彼此同步?
到目前为止,我们的方法是,每个客户都拥有计算和/或执行所有可能的操作所需的所有信息。实际上,除了游戏初始化阶段(添加玩家、选择地图等)之外,客户端拥有所有可用信息,该阶段需要一个“超级客户端”以及一些额外的东西来控制事物。
这是我们方法的标准场景:
- 玩家执行操作,该操作有效并在玩家客户端上执行,
- 操作通过网络发送,
- 操作在其他客户端上执行
我们提出的设计(即到目前为止没有或代码)到目前为止,类似于下面的伪序列图。
Gui、控制器和网络将所有可能的操作(即更改数据的所有操作)实现为接口中的方法。因此每个部分都可以以某种方式实现该方法来完成他们的工作。
Action() 示例:
在玩家端的客户端上:
Player-->Gui.Action()
Gui-->Controller.Action()
Controller-->Logic.Action
(Logic.Action() == NoError)?
Controller-->Network.Action()
Network-->Parser.ParseAction()
Network.Send(msg)
在所有其他客户端上:
Network.Recv(msg)
Network-->Parser.Deparse(msg)
Parser-->Logic.Action()
Logic-->Gui.Action()
问题:
这是完成我们任务的可行方法吗?
有更好/更简单的方法吗?
建议、批评?
我们的知识(以便您可以更好地确定您的答案):
我们处于初学者方面,涉及用小团队对较大的项目进行编程。 我们所有人都具有一些一般编程经验以及对 .Net 库和 Windows 窗体的基本了解。
如果您需要任何进一步的信息,请随时询问。
my first question here, so please don't be to harsh if something went wrong :)
I'm currently a CS student (from Germany, if this info is of any use ;) ) and we got a, free selectable, programming assignment, which we have to write in a C++/CLI Windows Forms Application.
My team, two others and me, decided to go for a network-compatible port of the board game Risk.
We divided the work in 3 Parts, namely UI, game logic and network. Now we're on the part where we have to get everything working together and the big question mark is, how to get the clients synchronized with each other?
Our approach so far is, that each client has all information necessary to calculate and/or execute all possible actions. Actually the clients have all information available at all, aside from the game-initializing phase (add players, select map, etc.), which needs one "super-client" with some extra stuff to control things.
This is the standard scenario of our approach:
- player performs action, the action is valid and got executed on the players client
- action is sent over the network
- action is executed on the other clients
The design (i.e. no or code so far) we came up with so far, is something like the following pseudo sequence diagram.
Gui, Controller and Network implement all possible actions (i.e. all actions which change data) as methods from an interface. So each part can implement the method in a way to get their job done.
Example with Action():
On the player side's Client:
Player-->Gui.Action()
Gui-->Controller.Action()
Controller-->Logic.Action
(Logic.Action() == NoError)?
Controller-->Network.Action()
Network-->Parser.ParseAction()
Network.Send(msg)
On all other clients:
Network.Recv(msg)
Network-->Parser.Deparse(msg)
Parser-->Logic.Action()
Logic-->Gui.Action()
The questions:
Is this a viable approach to our task?
Any better/easier way to this?
Recommendations, critique?
Our knowledge (so you can better target your answer):
We are on the beginner side, in regards to programming on a somewhat larger projects with a small team.
All of us have some general programming experience and basic understanding of the .Net Libraries and Windows Forms.
If you need any further information, please feel free to ask.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我所知道的是,我不会说 C++ 是一种适合初学者的语言!我从未使用过它,但我的朋友将其描述为“男人的语言”。我猜它会让你胸口长毛。
我从来没有写过这样的应用程序,虽然有些人会说 Winforms/胖客户端正在卷土重来,但我认为大多数人都会进行基于 Web 的开发。
我想 WCF 是一个合乎逻辑的地方,但我以前没有将它用于点对点的东西。
您如何知道还有哪些其他客户端,以便您可以与他们一起玩?
电话会议解决方案似乎使用集中式系统:您拨入特定号码,它会告诉您您是第一个加入会议的人。如果有人离开,其他人仍然在那里。这可能更符合您的需求——让中央系统调解数据。如果两个客户端发送冲突的操作会发生什么?
有了中央系统,您就可以建立直接的规则来管理游戏,并且更容易管理。您可以将肌动蛋白的处理包装在事务中,这样就不会发生冲突。唯一的问题是保持所有客户端同步;他们所要做的就是从中央服务器获取更新 - 但他们什么时候这样做呢?他们只是进行轮询还是在发生变化时由中央服务器“告知”?后者可能要好得多 - 但我不知道你会如何使用你提议的技术来做到这一点。
我希望这有帮助。
All I know is that I wouldn't say C++ is a language for beginners! I've never used it, but friends of mine who have descibe it as "a man's language". I guess it puts hairs on your chest.
I've never written an app like this, and whilst some would say Winforms / thick clients are making a come-back I think the majority of peopel out there will be doing web-based development.
I guess WCF would be a logical place to look, but I haven't used it for peer-to-peer stuff before.
How do you know which other clients are out there, so you can play with them?
Teleconferenceing solutions seem to use a centralised system: you dial into a specific number and it tells you you're the first person to join the conference. If someone leaves everyone else is still there. This might be more what you're after - let a central system mediate the data. What happens if two clients send conflicting actions?
With a central system you'd be able to build straight forward rules to govern the game, and it'd be easier to manage. You can wrap teh handling of actins in a transaction so that you don't get conflicts. the only issue then is keeping all the clients sync'd up; all they have to do is get an update from the central server - but when do they do that? do they just poll it or are they "told" by the central server when there's been a change? The latter is probably much better - but I don't know how you'd do it using the technology you're proposing.
I hope that helps.
一般来说,这个想法看起来不错。
为了用伪代码证明这个想法,您可以设计小型原型。
由于您想要构建的游戏是回合制的 - 您需要有保证的网络传输。
为了简化数据传输,您可以使用 proto buff 库
Generally the idea looks okay.
To prove the idea in pseudo code you can design small prototype.
Since, the game you want to build is turn based - you need guaranteed network delivery.
For data transfer simplification you can use proto buff library