'Is there a better way to get/store information about a item than my current method?
If I have created a new enum for example:
enum itemName{
shortsword, ironChestplate, leatherCap}
And for each of those items I had fixed information about each item, what would be the best way to store and retrieve the data? Currently I use a series of conversion methods that use switch statements to return the correct information, for example:
itemType convertItemNameToItemType(itemName itemName){
switch(itemName){
case itemName.shortsword:
return itemType.handEquipment;
case itemName.ironChestplate:
return itemType.bodyEquipment;
case itemName.leatherCap:
return itemType.headEquipment;
}
}
int convertItemNameToItemCost(itemName itemName){
switch(itemName){
case itemName.shortsword:
return 3;
case itemName.ironChestplate:
return 8;
case itemName.leatherCap:
return 2;
}
}
These are just examples but there are more conversion methods to return more information about the said item, as well as many more items. This means that there is a lot of bulky code with the amount of switch statements.
Is there a better way to store and retrieve this information? This information will not be changed throughout the running of the program.
Thanks.
Edit: By better I mean a more efficient and less bulky way to gather the information about a enum, rather than just using a switch statement. The data I may want to get is (more columns are needed but this is just a example):
| itemName | itemType | itemCost | itemTrainingRequirement |
|---|---|---|---|
| shortsword | handEquipment | 3 | martial |
| ironChestplate | bodyEquipment | 8 | martial |
| leatherCap | headEquipment | 2 | none |
and currently I only have switch statements to convert from one to another when I need to.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
