在许多类之间共享“stats类”(Sharing “stats class” between many classes)
我有我的移动课程,它将定义玩家,敌人,移动设备......我有一个项目类,这是不言自明的...
让我们说为了这个例子,我们有三个统计数据,
-> Strength -> Dexterity -> Intelligence
我计划在我的手机上有这些统计数据,而在我的项目上,如果我的项目与0不同,那么它们就是我的手机的修饰符。
我应该如何在课堂上存储这些内容?
它应该是这样的:
MY_Item { var $stats_dex; var $stats_int; var $stats_str; }
或者也许还有另一个班级,“统计课程”,其他课程也会有......?
MY_Item { var $stats = new MY_Stats; }
我的手机也一样吗?
因为在我的手机中,我也必须计算配备的物品......所以我最终会得到类似的东西:
class MY_Mobile { var $stats_dex; var $stats_int; var $stats_str; var $modifier_stats_dex; var $modifier_stats_int; var $modifier_stats_str; }
现在我正在使用第一个原型,但我已经对此感到不安......
I have my mobile class, which will define players, enemies, well mobiles... I have an item class, which is self-explanatory...
Let's say for the sake of the example that we have three stats,
-> Strength -> Dexterity -> Intelligence
I was planning to have theses stats on my mobiles, and on my items, if on my items they are different from 0, they therefore are modifiers of my mobiles.
How should I store these in my classes ?
Should it be like this :
MY_Item { var $stats_dex; var $stats_int; var $stats_str; }
Or maybe have another class, "Stats class" that every other class would have too... ?
MY_Item { var $stats = new MY_Stats; }
Same for my mobiles ?
Because in my mobiles, I'll have to compute the equiped items too... So I would end up with something like :
class MY_Mobile { var $stats_dex; var $stats_int; var $stats_str; var $modifier_stats_dex; var $modifier_stats_int; var $modifier_stats_str; }
Right now I'm working with the first prototype, but I'm already feeling uneasy about it...
原文:https://stackoverflow.com/questions/22597138