我如何设置单人游戏中收集金币的限额?

问题描述 投票:-1回答:1

我想在我的C#单机游戏中限制我的金矿。我希望有10个金币,在收集它们之后有新的金币。每5秒2新金。这在我的代码中很完美。但是现在我希望等待黄金之后有限制。如果玩家等待很长时间,他只能获得10金。但是限制不起作用。有什么想法吗?

这是我的代码:

public static void CollectGold(ObjectFactory.ObjectType type)
{
    if (sMaxGold > 0)
    {
        Hud.mGold += 2;
        sMaxGold -= 2;
    }
    if (Hud.mCurrentTime >= Hud.mCountDuration)
    {
        Counter++;
        Hud.mCurrentTime -= Hud.mCountDuration
        if (sMaxGold < 10)
        { 
            sMaxGold += 2;
        }
        if (sMaxGold >= 10)
        {
            sMaxGold -= 2;  // or sMaxGold = 10 in earlier version-> same output 
        }
     }                   
}

sMaxGold是我的极限。这永远不会超过10。但是每5秒钟我就会获得2新金。因此限制不起作用。有没有人可以帮助我?

c# counter limit monogame
1个回答
0
投票

如果hud.mGold <= sMaxGold,则您永远都不会进行比较。检查玩家的金币是否已达到maxGold应该是您的逻辑的一个条件,这似乎丢失了。

© www.soinside.com 2019 - 2024. All rights reserved.