i am making a board-game in C# under .NET (i am new in this)
now i am at the design stage

in my game there are four resources - food, stone, gold & wood - that uses for gathering, buy stuff etc. like in a classic strategy game (age of empires for example)

i thought of the implementation of that issue in the game and i got to the idea to make a Resource Class that will contain the 4 resources fields.
if for example - building something cost 200 gold & 100 stone the Resource Instance will be with 200 in gold, 100 in stone and 0 in the others
the treasury of each player will be Resource instance too, and when buying the building it will remove 200 gold and 100 stone from it.

i didn't wanna to make a differnt class for each resource because i didnt find that useful, but now i am not so sure in this - i feel that it's wrong to do it like that, i mean its somehow ruin the rules of good OOP & Design Patterns principles.

do you have advise on how to design the resources part of the game?
hope you understand my question.
Thank u,

the code:

public class Resources 
private uint _food;     
private uint _wood;     
private uint _stone;     
private uint _gold;      

public uint Food     
get { return _food; }         
set { _food = value; }     
public uint Wood     
get { return _wood; }         
set { _wood = value; }     
public uint Stone     
get { return _stone; }         
set { _stone = value; }     
public uint Gold     
get { return _gold; }         
set { _gold = value; }     

#region Constructors     
public Resources(uint food, uint wood, uint stone, uint gold)     
_food = food;         
_wood = wood;         
_stone = stone;         
_gold = gold;     

public Resources(Resources res)     
_food = res.Food;        
_wood = res.Wood;         
_stone = res.Stone;         
_gold = res.Gold;     

public void Add(Resources res)     
_food += res.Food;         
_wood += res.Wood;         
_stone += res.Stone;         
_gold += res.Gold;     

public void Remove(Resources res)     
_food -= res.Food;         
_wood -= res.Wood;         
_stone -= res.Stone;         
_gold -= res.Gold;     

Edited by galhajaj: n/a

6 Years
Discussion Span
Last Post by hericles

Well you could make subclasses wood, gold, stone and food of the super class Resource. essentially they would be basic classes and use the implementation of the Resources class for most things, unless something specific arises. But then you would have easily identifiable classes in code that follow similar rules.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.