Hello everyone, OK I need to design a way to keep track of how many of each item exists. There are approximately 26 items. I also need a way to find out if a certain combination of items exist.
For example, This is an engine for a card game. Each card has a different type and each card can have card attached to it. There need to be a certain combination of cards attached to a card for the player to do certain things in the game. To make this program streamlined, I would like to do something like
if (meetsCrit(2, water, 4, ground))
{
do this()
}
else
{
displayerror()
}
Thanks, -Michael
EDIT: SOLVED! I used a combination of techniques described in a few post below. Special mention to:
Jon Skeet, Rinat Abdullin, Frank,
Anyway here is what I did I made a class called pair which stores the type I'm looking for, and the number of that type. Then I used a Predicate Delegate to find all of that type and count how many there are, Then I compared it to number I was searching for and returned true or false respectively.
This is the code for it
public bool meetsCrit(params Pair[] specs)
{
foreach (Pair i in specs)
{
if (!(attached.FindAll(delegate(Card c) { return c.type == i.type; }).Count >= i.value))
{
return false;
}
}
return true;
}