c# - Best inheritance / interface structure for storing many game constants? -
i have game data structured this:
public class craftablefiretower { public static list<resourcenumber> requiredresources = new list<resourcenumber> { new resourcenumber(resourcetype.wood, 100), new resourcenumber(resourcetype.stone, 50) }; } public class craftablefrosttower { public static list<resourcenumber> requiredresources = new list<resourcenumber> { new resourcenumber(resourcetype.wood, 120), new resourcenumber(resourcetype.stone, 70) }; } which combination of interfaces, abstract classes, inheritance, static methods / classes can use make them generic can pass them methods without creating new instances of classes every time?
if (inventory.hasresourcesfor(craftablefiretower)) { inventory.removeresourcesfor(craftablefiretower); serverworld.buildfiretower(position)); } i tried interface, can't have static methods on interface. tried abstract class can't make static abstract class or static abstract method. i'm trying impossible? there better way structure hard-coded grouped numbers/constants game data?
i think factory class queried find cost of returns instances of things if requested.
metainfo firemeta = new metainfo(100, 50); factory.registercraftable(craftablefiretower, firemeta); with
factory.getrequirements<craftablefiretower>(); and
factory.new<craftablefiretower>(); internally factory uses dictionary store meta information each craftable instance such resources , build time.
the idea others have mentioned separate information class class itself
Comments
Post a Comment