【问题标题】:Keeping track of game state for a Card Trading Game跟踪纸牌交易游戏的游戏状态
【发布时间】:2013-12-08 01:52:21
【问题描述】:

我正在开发一款纸牌游戏。假设它类似于万智牌、炉石传说等。

我试图弄清楚的问题是如何构建“光环”以及每张卡会受到多少伤害。

现在我有一个套牌,我存储卡片数据如下。我已经为将存在的卡片类型编造了名称。

M.card = {}
-- Minion cards have health and damage
M.card[1].name = "Minion"
M.card[1].hp = 1
M.deck[1].dmg = 1

-- Super Minions have more health and damage
M.card[2].name = "Super Minion"
M.card[2].hp = 4
M.card[2].dmg = 4

-- Spell cards have no health and damage. Instead they affect the health and damage of other cards.
M.card[3].name = "Heal"
M.card[3].details = "This card heals any character for +2 health"
M.card[3].healthboost = 2

M.card[4].name = "Damage Boost"
M.card[4].details = "This card gives + 1 damage to any other card for 1 turn"
M.card[4].dmgboost = 1

-- Super damage boost gives more damage boost to other cards
M.card[5].name = "Super Damage Boost"
M.card[5].details = "This card gives +3 damage to any other card permanently"
M.card[5].dmgboost = 3

所以当一张牌攻击另一张牌时,我需要记录两张牌受到的伤害。我不想更改每张卡的基本数据,所以我需要跟踪调整。

我可以做这样的事情

-- Super Minion takes 3 damage
M.card[2].newHp = 1   
-- or 
M.card[2].adjHp = -3 
-- Not sure which is better.

在战斗中,我需要跟踪使用了哪些光环。例如,如果打出伤害提升卡。我需要在一个回合内给另一张卡+1伤害。

假设我从 1 开始跟踪每个回合数。

我应该这样做吗

M.aura[1] = 4   -- ( aura 1 is card # 4)
M.aura[1].target = 2   -- (this aura is applied to card 2)
M.aura[1].expires = 5  -- (this aura expires on turn 5)

M.aura[2] = 3   -- ( second active aura is heal, card #3 )
M.aura[2].target = 2
M.aura[2].expires = 0   -- this is a one time aura.  So I need to apply it to card #2 and then immediately expire it so it never activates again.

然后在每个新的回合中,我都会遍历所有光环,并确保它们在战斗开始前仍然处于活动状态?

只是想知道在架构上记录角色受到的伤害以及赋予角色特殊能力的有效法术的最佳方法是什么。

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    为什么不将卡片实例化为在游戏过程中永远不会更改的不可变参考卡片,并与实例的父级进行比较?你可以通过一些简单的object orienting 来做到这一点。

    或者,如果这不适合你,你可以给每张卡一个最大或基本 HP 字段。

    table.insert(M.card, {
        name = "Wizard",
        hp = 10,
        basehp = 10,
        dmg = 5
    })
    

    至于卡牌的限时效果,你可以在卡牌本身上追踪。

    M.card[1].effects = { { dmgboost = 2, expires = 3 } }
    

    给基础卡一个函数,让它根据效果计算卡的统计数据。

    function Card:damage()
        local d = self.dmg
        for _, v in ipairs(self.effects) do
            if v.dmgboost then d = d + v.dmgboost end
        end
        return d
    end
    
    function Card:processEffects()
       for i = #self.effects, 1, -1 do
           if turn >= self.effects[i].expires then
               table.remove(self.effects, i)
           end
       end
    end
    

    这些只是您可以处理的许多方法中的几个示例。不过,我相信这足以让您暂时获得一些想法。

    【讨论】:

    • 我喜欢这种方法。但是我如何处理其他卡给出的效果,当其他卡被破坏时这些效果会消失。假设卡 1 对所有其他友方卡造成 +1 伤害。我不想为所有卡添加 +1 伤害效果,并将到期时间与原始卡的死亡联系起来。相反,将效果绑定到提供效果的卡片可能更有意义,因此当卡片死亡时,效果会自动从所有卡片中移除。但是你会如何编程呢?
    • @fun_programming 你可以给效果一个指向给他们效果的卡片的字段,例如dependsOn,然后当你处理效果以移除或以其他方式处理它们时,检查如果从属卡仍在游戏中,如果没有,则移除效果。
    【解决方案2】:

    为了使一张牌的存在暂时影响另一张牌的品质,请使用观察者或回调模式。当您“抽出”(从牌组或手牌中)为所有其他友方牌增加 +1 伤害的特殊牌时,大概您有一个功能 findAllOtherFriendlyCards(yourSpecialCard, allCards) 可以做到这一点。然后在此函数中,对于您找到的每张友方卡,您通过调用specialCard:registerDiscard(yourFriendlyCard) 将友方卡“注册”到特殊卡上。然后,当特殊卡被丢弃时,大概是通过调用specialCard:discard() 发生的,此方法查看所有已注册的卡并重新调整特殊卡影响的属性。

    其实你不需要一个单独的注册方法,你可以有一个specialCard:startEffect(friendlyCard):这个方法调整friendlyCard的一些属性,并把它保存在一个列表中;而你有一个specialCard:endEffect(friendlyCard),它做相反的事情,即在相反的方向调整属性(如果它在开始时为-1,则+1,等等)并将卡片从受影响的卡片列表中删除。

    如果在特殊卡被丢弃之前可以丢弃友方卡,您可以使用类似的技术:友方卡必须跟踪每张调整它的特殊卡并在它被丢弃时通知特殊卡,因此特殊卡可以将其从列表中删除。

    【讨论】:

      猜你喜欢
      • 2015-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-02
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多