卡牌游戏设计

发布于 2024-11-17 03:30:59 字数 435 浏览 2 评论 0原文

我正在创建一款多人纸牌游戏。 我有两个主要类:

我的问题是经理和球员之间关系的最佳设计是什么。 我认为主教练应该认识所有球员,但球员不应该认识他...... 这是因为,如果有一天我想将玩家类用于其他纸牌游戏,它将非常通用。

为了使用我的设计,我应该为 Player 类创建许多事件。 例如getCardFromTheDeck

什么是最好的设计?

I'm creating a multiplayer card game.
I have two main classes:

  • Player - represents a player in the game.

  • Manager - is the manager of the game.. it is a singleton and holds the the main card deck and all the Players.

My question is what is the best design for the relationship between Manager and Player.
I think that Manager should know all the players but the players should not know him...
that's because if one day I will want to use the player class for other card games it will be very generic.

In order to use my design I should create many events for the Player class.
for example getCardFromTheDeck.

What is the best design?

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

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

发布评论

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

评论(1

好听的两个字的网名 2024-11-24 03:30:59

游戏的设计应该很大程度上取决于您的要求,这样您的问题就太混乱了,而且没有建设性。

我会给你一个你所要求的例子:我想说一个普通的游戏应该有一个游戏板、玩家和游戏控制器(至少)。棋盘上应该有所有已放下的牌、未抽出的牌等的集合。玩家应该有他们拥有的当前牌的集合。游戏控制器应该具有诸如开始游戏、确定获胜者等方法...

对于游戏逻辑,您可以具有诸如策略模式之类的东西,您需要某种表达规则的方式等......

并且您继续这样思考。了解基本的 OO 原则,例如 SOLID,这是最重要的单一责任原则。

有关可为您提供想法的设计模式指南,请参阅 GoF 设计模式。更多例子,网上找一些游戏源代码,研究一下。您会得到一些想法,您的设计将从中受益。

Design of you game should be decided heavily on your requirements, your question is too confusing this way, and not constructive.

I'll give you an example of what you are asking: I would say that an average game should have a game board, players and game controller (at very least). Board should have a collection of all the cards laid down, not drawn etc... Players should have collection of current cards they possess. Game controller should have methods like start game, determine winner etc...

For game logic you can have something like Strategy patterns, you need some way of expressing rules etc...

... and you continue thinking like this. Be aware of basic OO priciples, like SOLID, most important of all Single Responsibility Principle.

For design patterns guidance that can give you ideas, refer to GoF Design Patterns.For more examples, find some game source codes online and study them. You will get some ideas, and from those, your design will benefit.

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