我在将卡实际打印到控制台窗口时遇到问题有什么想法吗?另外,欢迎对我的代码提出任何建议。
namespace Drinking_Game_
{
class Program
{
这是我遇到一些麻烦的地方。我无法将调用的卡片打印到 ConsoleWindow。
public static void Main()
{
Deck deck = new Deck();
Card card = new Card();
deck.Shuffle();
var value = deck.TakeCard();
Console.WriteLine(value);
Console.ReadLine();
}
}
public enum Suit
{
Spades = 0,
Hearts = 1,
Diamonds = 2,
Clubs = 3,
}
public enum CardNumber
{
Ace = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9,
Ten = 10,
Jack = 11,
Queen = 12,
King = 13,
}
public class Card
{
public Suit Suit { get; set; }
public CardNumber CardNumber { get; set; }
}
public class Deck
{
public Deck()
{
Reset();
}
public List<Card> Cards { get; set; }
public void Reset()
{
Cards = Enumerable.Range(1, 4)
.SelectMany(s => Enumerable.Range(1, 13)
.Select(c => new Card()
{
Suit = (Suit)s,
CardNumber = (CardNumber)c
}
)
).ToList();
}
public void Shuffle()
{
Cards = Cards.OrderBy(c => Guid.NewGuid()).ToList();
}
public Card TakeCard()
{
var card = Cards.FirstOrDefault();
Cards.Remove(card);
return card;
}
public IEnumerable<Card> TakeCards(int numberOfCards)
{
var cards = Cards.Take(numberOfCards);
var takeCards = cards as Card[] ?? cards.ToArray();
Cards.RemoveAll(takeCards.Contains);
return takeCards;
}
}
}