设计一款集换式卡牌游戏

发布于 2024-11-25 04:07:04 字数 747 浏览 3 评论 0原文

我正在尝试学习如何用 Javascript 编写(虚拟)集换式卡牌游戏(类似于 Magic the Gathering)。我读过一些有关 MVC 架构和控制器的内容,但这些都在我的脑海中(我没有接受过任何正式的 CS 教育),我想知道是否有人有任何好的链接或提示来帮助我了解如何更多地了解代码初学者水平的架构。

每张“卡牌”是否会被表示为一个对象,并且卡牌规则的所有逻辑都被包装在一个大型游戏引擎函数中,还是许多彼此连接的小函数中?

这是一个示例问题: 想象有一张牌,上面写着:“当这张牌发挥作用时,抓一张牌。”我应该如何构建游戏来为这种情况做好准备,以及如何触发它(最有效)?该卡牌是否触发游戏引擎,或者游戏引擎是否解析每张打出的卡牌?

这是另一个例子: 想象一下有一张牌,上面写着:“你所有的牌的打牌成本都减少了 1。”并且它会永久地发挥作用。在这种情况下,游戏如何理解需要改变规则?这是一个监听要打牌并中断费用的功能吗?每回合结束时,该规则存储在哪里?是否有存储游戏基本规则的变量(全局卡牌成本修正值:0;你的卡牌成本修正值:0)以及存储卡牌引入的新规则的其他变量(你的卡牌成本修正值:-1),或者是这些当卡牌改变规则时,游戏引擎动态创建的变量(你的精灵成本修正值:-2)?当卡牌被破坏时,规则如何知道要改变,从而消除卡牌的规则修改?

我需要了解听众和事件的入门知识吗? (我对它们一无所知,但我时不时地看到对它们的引用。)您能给我指出一个好的资源的方向吗?

需要明确的是,我并不是想冗长地要求人们为我手动搜索谷歌;我盲目地在黑暗中摸索,询问是否有人能给我指出要搜索的正确单词或短语。谢谢你!

I'm trying to learn how to program a (virtual) Trading Card Game game (similar to Magic the Gathering) in Javascript. I've read a little about MVC architecture and controllers, but it's all over my head (I don't have any formal CS education) and I'm wondering if anyone has any good links or tips about how I might learn more about code architecture at a beginner's level.

Would each "card" be represented as an object, and all the logic of the cards' rules be wrapped inside one large game engine function, or many small functions that are connected to each other?

Here's an example question:
Imagine there's a card which says, "When this card comes into play, draw a card." How should I architect the game to prepare for this situation, and how is it triggered (most efficiently)? Does the card trigger the game engine, or does the game engine parse each card that's played?

Here's another example:
Imagine there's a card which says, "All your cards cost 1 less to play." and it stays in play permanently. How does the game understand that it needs to alter its rules in this case? Is this a function which listens for card to be played and interrupts the cost? As each turn resolves, where is this rule stored? Are there variables which store the base rules of the game (global card cost modifier: 0; your card cost modifier: 0) and other variables which store those new rules which cards introduce (your card cost modifier: -1), or are these variables dynamically created by the game engine as cards alter the rules (your elf cost modifier: -2)? And how do the rules know to change when a card has been destroyed, thus removing the card's rule modification?

Is what I need a primer on listeners and events? (I don't really know anything about them, but I've seen references to them from time to time.) Could you point me in the direction of a good resource?

To be clear, I'm not trying to make a long-winded request for folks to manually Google for me; I'm blindly fumbling in the dark and asking if someone would point me to the right words or phrases to search. Thank you!

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

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

发布评论

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

评论(2

隔纱相望 2024-12-02 04:07:04

有一个非常好的博客关于重新创建类似的纸牌游戏:来自暴雪的炉石传说。尽管它是用 C# 编写的并使用 Unity 作为视图层,但您可以很好地理解如何为此类游戏创建合适的架构。不过,一个公平的警告是,用 Javascript 重新创建万智牌可能会非常复杂,并且会让你的头脑很混乱(我有第一手经验)。

博客:http://theliquidfire.com/2017/08/21 /make-a-ccg-intro/

There is a very nice blog about recreating a similar card game: Hearthstone from Blizzard. Allthough it is written in C# and uses Unity as a view layer, you get a pretty good understanding of how one goes about creating a suitable architecture for such a game. A fair warning though, recreating Magic the Gathering in Javascript can prove incredibly complicated and mess with your head a lot (I have first hand experience).

Blog: http://theliquidfire.com/2017/08/21/make-a-ccg-intro/

心欲静而疯不止 2024-12-02 04:07:04

你需要在这里更深入地思考“游戏”本身。您所描述的游戏实际上是围绕“状态机”构建的,这是一个核心 CS 概念,您应该在开始构建之前深入研究并理解。

您的游戏规则将成为一个状态机,并且在游戏期间触发(通过玩)的事件(卡牌)可以修改这些规则。您需要某种解释器来“读取”卡片并修改规则或游戏状态。然后,您需要一些东西来通过回合和阶段迭代游戏,读取状态并采取适当的行动。

您还需要了解堆栈。如果您的游戏允许玩家互相打断,您将需要一种方法来跟踪哪个事件应该首先发生,因为事件希望能够影响、阻止、重定向其他事件。堆栈将帮助您跟踪该顺序。

You need to go a level deeper here and think about the "game" itself. The game you're describing will actually be built around a "state machine" which is a core CS concept you should dive into and understand before you start building.

The rules of your game are going to be a state machine and the events (cards) triggered (by being played) during your game can modify those rules. You'll want some kind of interpreter to "read" the card and to modify either the rules or the game state. And then you'll need something to iterate the game through turns and phases, reading the state and taking appropriate action.

You'll also want to learn about stacks. If your game lets players interrupt each other you'll need a way to keep track of which event should happen first because events will want to be able to affect, block, redirect other events. A stack will help you keep track of that ordering.

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