My game has 4 supplies, Gold Wheat Iron Fuel
, a player is allowed to select a supply to trade and what supply to receive from merchant NPCs.
Currently, when the user trades an item I have the following logic I am using c# but this is not the exact code used.
if(sellGold){
if(buyGold){
tradeRatio = .5;
}
if(buyWheat){
tradeRatio = 3;
}
}
else if(sellIron){
if(buyGold){
tradeRatio = 1;
}
if(buyFuel){
tradeRatio = 2;
}
}
...etc
Where the amount a player receives is calculated by multiplying the trade ratio by the amount sold.
This works, it is just rather tedious and would be a pain to add more supplies later. What would a better approach be? I'm thinking of assigning each item a value and that value is different based on the trade type, but that still involves a whole bunch of nested conditionals.
Enum
type, but what you can and cannot do with Enum's will depend a lot on the programming language. – Tartle Wizard Dec 05 '16 at 22:36