【问题标题】:C++ simple text RPG game, type of creature and quantity [closed]C ++简单文本RPG游戏,生物类型和数量[关闭]
【发布时间】:2014-05-10 14:39:25
【问题描述】:

我刚刚开始用 C++ 编写简单的 RPG 游戏。会有一个类(模式,不是代码)

class creature
    string name;
    int hp, strength...

也会有数量。但是如果我想创建两组相同类型的生物,例如:('a', 100, 10)',那么单独制作它们会浪费时间和内存,将名称和所有其他参数写两次,只是数量不同。你知道有什么方法可以实现生物堆叠数量,而无需重复数据吗?

因为我刚刚开始工作,所以我会尝试做一些事情并告诉你结果。

【问题讨论】:

    标签: c++ class object


    【解决方案1】:

    如何将它包装在一个代表数量的类中? 我的意思是

    class CreatureGroup {
        Creature creature;
        int quantity;
    };
    

    【讨论】:

    • 好的,它可以工作。现在我在考虑构造函数:) 你有什么想法吗?
    • 写一个带有Creatureint的。它看起来像这样。 public CreatureGroup(Creature cre,int quant):creature(cre),quantity(qua){}
    猜你喜欢
    • 2013-07-27
    • 2016-11-19
    • 2022-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-10
    • 1970-01-01
    相关资源
    最近更新 更多