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,
Gal

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;     
}      
#endregion       

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;     
} 
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.