哪种设计模式最适合 AS3 中的 RTS 游戏?

发布于 2024-11-18 09:34:52 字数 144 浏览 8 评论 0原文

我正在寻找一些关于设计模式的好书,并且我想知道您会为实时策略游戏(例如星际争霸)、MVC 推荐哪种特定模式?

我想在某个时候在 Flash 中制作一个基本的 RTS,并且我想开始研究为此的最佳模式。

干杯!

I'm looking to get some good books on design patterns and I'm wondering what particular pattern you'd recommend for a Realtime Strategy Game (like Starcraft), MVC?.

I'd like to make a basic RTS in Flash at some point and I want to start studying the best pattern for this.

Cheers!

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

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

发布评论

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

评论(3

绅士风度i 2024-11-25 09:34:52

这类问题的问题是答案完全取决于你的设计。即使是简单的 RTS 游戏也很复杂。他们有许多必须协同工作的系统,并且每个系统都必须以不同的方式设计以实现共同的目标。

但这里要稍微谈一下。

即时战略中的人工智能系统通常有几个不同的级别。单元级人工智能可以像基于开关的状态机一样简单,一直到完整的行为树(复合/装饰器)。
您通常还需要某种类型的战略级人工智能高级规划系统。 (指挥官等级和AI玩家)
在这些层和资源管理器等一些辅助事物之间通常有几个级别。
您还可以使用基于事件的系统,它也与 Flash 的基于事件的模型很好地结合在一起。

对于主游戏引擎本身,可以轻松实现基本状态机(从基于开关到基于功能再到基于类的任何状态机)以将所有内容结合在一起并与菜单系统结合起来。

对于个人玩家来说,模型-视图-控制器是一种非常自然的目标模式,因为您希望 AI 玩家能够接触到人类玩家可以访问的所有内容。因此,唯一的变化是控制器(大脑),显然不需要视图。

正如我所说,这不是像普通的 stackoverflow 问题一样可以回答的问题,它完全取决于设计以及您决定如何实现它。 (就像大多数事情一样)有大量关于 RTS 游戏设计的资源,将其全部吸收是我真正能给出的唯一建议。即使是简单的 RTS 也是复杂的系统。

祝你好运,我希望这篇文章能让你了解如何思考它。 (记住,RTS 中的平衡就是一切)

The problem with this kind of question is the answer is it completely depends on your design. RTS games are complicated even simple ones. They have many systems that have to work together and each of those systems has to be designed differently with a common goal.

But to talk about it a little here goes.

The AI system in an rts usually has a few different levels to it. There is the unit level AI which can be as simple as a switch based state machine all the way up to a full scale behavior tree (composite/decorators).
You also generally need some type of high level planning system for the strategic level AI. (the commander level and the AI player)
There are usually a few levels in between those also and some side things like resource managers etc.
You can also go with event based systems which tie in nicely with flash's event based model as well.

For the main game engine itself a basic state machine (anything from switch based to function based to class based) can easily be implemented to tie everything together and tie in the menu system with that.

For the individual players a Model-View-Controller is a very natural pattern to aim for because you want your AI players to be exposed to everything the human player has access to. Thus the only change would be the controller (the brain) without the need for a view obviously.

As I said this isn't something that can just be answered like the normal stackoverflow question it is completely dependent on the design and how you decide to implement it. (like most things) There are tons of resources out there about RTS game design and taking it all in is the only advice I can really give. Even simple RTS's are complex systems.

Good luck to you and I hope this post gives you an idea of how to think about it. (remember balance is everything in an RTS)

昔日梦未散 2024-11-25 09:34:52

要支持大量单位,您可以使用 Flyweight对象池。 Flyweight 对象可以完全存储在大型 ByteArray 中的几个字节中。要获取可用的对象,请读取相应的字节,获取空对象并用这些字节中的数据填充它。对象池可以保存那些可用的对象,以防止不断分配/垃圾收集。这样,您可以在 ByteArray 中保存数千个单元,并通过数十个池化对象 shell 来管理它们。
应该注意的是,这更适合存储单元的图块属性,但是,图块或多或少是静态的,而单元是定期创建和销毁的。

To support lots of units, you might employ Flyweight and Object Pool. Flyweight object can be stored entirely in a few bytes in a large ByteArray. To get usable object, read corresponding bytes, take empty object and fill it with data from those bytes. Object pool can hold those usable objects to prevent constant allocation/garbage collection. This way, you can hold thousands of units in ByteArray and manage them via dozen of pooled object shells.
It should be noted that this is more suitable to store tile properties that units, however — tile are more-or-less static, while units are created and destroyed on regular basis.

南街女流氓 2024-11-25 09:34:52

熟悉一些设计模式并在适当的情况下将它们应用到游戏的架构中会很好。

例如,您可以为整个应用程序采用 MVC 架构、用于创建敌人的工厂模式、用于商店物品的装饰器模式等。重点是,设计模式只是用于构造对象的方法。如何定义这些对象以及如何决定它们如何组合在一起是非规定性的。

It would be good to be familiar with a number of design patterns and apply them to the architecture of your game where appropriate.

For example, you may employ an MVC architecture for your overall application, factory pattern for creating enemies, decorator pattern for shop items, etc. Point being, design patterns are simply methodologies for structuring your objects. How you define those object and how you decide how they fit together is non prescriptive.

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