卡牌游戏设计
我正在创建一款多人纸牌游戏。 我有两个主要类:
Player - 代表游戏中的玩家。
经理 - 是游戏的经理。它是一个单例< /a> 并持有主牌组和所有玩家。
我的问题是经理和球员之间关系的最佳设计是什么。 我认为主教练应该认识所有球员,但球员不应该认识他...... 这是因为,如果有一天我想将玩家类用于其他纸牌游戏,它将非常通用。
为了使用我的设计,我应该为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
游戏的设计应该很大程度上取决于您的要求,这样您的问题就太混乱了,而且没有建设性。
我会给你一个你所要求的例子:我想说一个普通的游戏应该有一个游戏板、玩家和游戏控制器(至少)。棋盘上应该有所有已放下的牌、未抽出的牌等的集合。玩家应该有他们拥有的当前牌的集合。游戏控制器应该具有诸如开始游戏、确定获胜者等方法...
对于游戏逻辑,您可以具有诸如策略模式之类的东西,您需要某种表达规则的方式等......
并且您继续这样思考。了解基本的 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.