移动项目表单列表<>到另一个。 C#

时间:2016-08-14 19:48:19

标签: c# .net console

我是编程的新手,也是c#的新手,我正试图为我正在学习的课程创建一个黑杰克游戏,并且我很早就遇到了麻烦。

我要做的是从一个列表中移动一个项目<>到另一个。或者如果它更容易;首先将项目添加到其他列表中,只需从原始列表<>中删除该项目。(或者如果我认为这完全错误,任何建议都会非常感谢)

所以将牌从牌组中移出:牌到另一张牌:playerHand

这是List<> "卡片组"

public Deck()
{
    //add card suits- 
    cards = new List<Cards>();
    // Hearts
    cards.Add(new Cards("Ace", "Hearts", 11));
    cards.Add(new Cards("2", "Hearts", 2));
    cards.Add(new Cards("3", "Hearts", 3));
    cards.Add(new Cards("4", "Hearts", 4));
    cards.Add(new Cards("5", "Hearts", 5));
    cards.Add(new Cards("6", "Hearts", 6));
    cards.Add(new Cards("7", "Hearts", 7));
    cards.Add(new Cards("8", "Hearts", 8));
    cards.Add(new Cards("9", "Hearts", 9));
    cards.Add(new Cards("Jack", "Hearts", 10));
    cards.Add(new Cards("Queen", "Hearts", 11));
    cards.Add(new Cards("King", "Hearts", 12));
    // Diamonds
    cards.Add(new Cards("Ace", "Diamonds", 11));
    cards.Add(new Cards("2", "Diamonds", 2));
    cards.Add(new Cards("3", "Diamonds", 3));
    cards.Add(new Cards("4", "Diamonds", 4));
    cards.Add(new Cards("5", "Diamonds", 5));
    cards.Add(new Cards("6", "Diamonds", 6));
    cards.Add(new Cards("7", "Diamonds", 7));
    cards.Add(new Cards("8", "Diamonds", 8));
    cards.Add(new Cards("9", "Diamonds", 9));
    cards.Add(new Cards("Jack", "Diamonds", 10));
    cards.Add(new Cards("Queen", "Diamonds", 11));
    cards.Add(new Cards("King", "DIamonds", 12));
    // Spade
    cards.Add(new Cards("Ace", "Spades", 11));
    cards.Add(new Cards("2", "Spades", 2));
    cards.Add(new Cards("3", "Spades", 3));
    cards.Add(new Cards("4", "Spades", 4));
    cards.Add(new Cards("5", "Spades", 5));
    cards.Add(new Cards("6", "Spades", 6));
    cards.Add(new Cards("7", "Spades", 7));
    cards.Add(new Cards("8", "Spades", 8));
    cards.Add(new Cards("9", "Spades", 9));
    cards.Add(new Cards("Jack", "Spades", 10));
    cards.Add(new Cards("Queen", "Spades", 11));
    cards.Add(new Cards("King", "Spades", 12));
    // Clubs
    cards.Add(new Cards("Ace", "Clubs", 11));
    cards.Add(new Cards("2", "Clubs", 2));
    cards.Add(new Cards("3", "Clubs", 3));
    cards.Add(new Cards("4", "Clubs", 4));
    cards.Add(new Cards("5", "Clubs", 5));
    cards.Add(new Cards("6", "Clubs", 6));
    cards.Add(new Cards("7", "Clubs", 7));
    cards.Add(new Cards("8", "Clubs", 8));
    cards.Add(new Cards("9", "Clubs", 9));
    cards.Add(new Cards("Jack", "Clubs", 10));
    cards.Add(new Cards("Queen", "Clubs", 11));
    cards.Add(new Cards("King", "Clubs", 12));
}

1 个答案:

答案 0 :(得分:2)

n=25

也许是一种更清洁的方式来创建所有卡片组:

Card cardToMove = cards[0];
cards.Remove(card);
playerHand.Add(card);