I am developing a card game and in this card game, you can build new cards up to the value of 10.
Before the player can build a new card he/she must first select a bunch of cards he wants to build with, each card that gets selected will be added to a list of selected cards.
What then needs to happen is the player must be shown what cards he can build using different combinations of the cards available in the list. e.g if you have a 2 and 3 in your list of selected cards you can build a 5 because of 2 + 3 = 5.
These combos will be added to a new list where the player will be able to select the new card he can build from that collection/combo
var listOfCardsSelected = new List<int>{2,5,6,8,7,3, 1};
// Get a list of card combo's that has a value <= 10 Combo e.g:
1 + 3 = 4 // This becomes a combo
2 + 5 = 7 // This becomes a combo
3 + 2 = 5 // This becomes a combo
6 + 2 = 8 // This becomes a combo
6 + 3 = 9 // This becomes a combo
7 + 3 = 10 // This becomes a combo
2 + 5 + 3 = 10 // This becomes a combo
2 + 5 + 1 = 8 // This becomes a combo
3 + 2 + 1 = 6 // This becomes a combo
6 + 3 + 1 = 10 // This becomes a combo
//OR another random variation
var listOfCardsSelected = new List<int>{2,5,2,8,1,3, 1};
1 + 1 + 3 + 2 + 2 = 9 // This becomes a combo
5 + 1 + 1 + 3 = 10 // This becomes a combo
5 + 2 + 2 + 1 = 10 // This becomes a combo
The example of code below works but it only returns combos that work with only 2 card combos, some combos need to be able to take bigger combos that take more values.
void CheckForCombo()
{
// For every card in our Selection
foreach(int cardValue in listOfCardsSelected)
{
int comboTotal = 0;
//Compare it to other cards
for(int i =0; i< listOfCardsSelected.Count; i++)
{
// Card cant use it's own value
if(listOfCardsSelected[i] != cardValue)
{
// If the value is <=10
if((cardValue + listOfCardsSelected[i]) <= 10)
{
comboTotal = cardValue + listOfCardsSelected[i];
comboCollection.Add(comboTotal);
}
}
}
}
}