So I made a deck of cards with enums. But now I need to delete all the cards from 2 to 6 in the different suits through a List<T>
. This piece of the code is given:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var d = new Deck();
Log(Converteer.ToString(d), "NIEUWE DEK");
// this works
d.RemoveNonManilleCards();
Log(Converteer.ToString(d, 8), "MANILLE-DECK");
// should be ->
// ♠A - ♠7 - ♠8 - ♠9 - ♠10 - ♠B - ♠D - ♠H
// ♥A - ♥7 - ♥8 - ♥9 - ♥10 - ♥B - ♥D - ♥H
// ♣A - ♣7 - ♣8 - ♣9 - ♣10 - ♣B - ♣D - ♣H
// ♦A - ♦7 - ♦8 - ♦9 - ♦10 - ♦B - ♦D - ♦H
And this is the deck being created and the void for deleting the cards. But I think I'm doing it completely wrong.
public partial class Deck : List<Card>
{
public Deck()
{
MakeDeck();
}
protected virtual void MakeDeck()
{
foreach (Suit k in System.Enum.GetValues(typeof(Suit)))
{
foreach (Rank n in System.Enum.GetValues(typeof(Rank)))
{
this.Add(new Card(k, n));
}
}
}
public void RemoveNonManilleCards()
{
foreach (Suit k in System.Enum.GetValues(typeof(Suit)))
{
foreach (Rank n in System.Enum.GetValues(typeof(Rank)))
{
this.RemoveRange(1, 5);
}
}
}
Can some of you point me in the right direction?
I think that I found how to fix the problem
public void RemoveNonManilleCards()
{
for (int index = Count - 1; index >= 0; --index)
{
Kaart kaart = this[index];
if (card.rank>= Rank.Two&& card.Rank<= Rank.Zes)
this.RemoveAt(index);
}
Thanks for the answers!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.