using System;
using System.Collections.Generic;
namespace ConsoleApp1
{
class Program
{
static Random rng = new Random();
static void Main(string[] args)
{
var deck = GetFullDeck();
var hand1 = new List<Card>();
var hand2 = new List<Card>();
// Deal two hands of five cards.
Deal(5, deck, hand1, hand2);
Console.WriteLine("Player 1 is holding the following hand:");
foreach (var card in hand1)
{
Console.WriteLine(card.ToString());
}
Console.WriteLine();
Console.WriteLine("Player 2 is holding the following hand:");
foreach (var card in hand2)
{
Console.WriteLine(card.ToString());
}
Console.ReadLine();
}
static List<Card> GetFullDeck()
{
var deck = new List<Card>();
// Populate the deck with every possible card.
foreach (Face face in Enum.GetValues(typeof(Face)))
{
foreach (Suit suit in Enum.GetValues(typeof(Suit)))
{
deck.Add(new Card(face, suit));
}
}
return deck;
}
static void Deal(int cardCount, List<Card> deck, params List<Card>[] hands)
{
for (int i = 0; i < cardCount; i++)
{
// Deal one card to each hand at a time.
foreach (var hand in hands)
{
// Select a card from the deck at random.
var index = rng.Next(0, deck.Count);
var card = deck[index];
// Remove the card from the deck and add it to the current hand.
deck.Remove(card);
hand.Add(card);
}
}
}
}
enum Face
{
Ace = 1,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King
}
enum Suit
{
Hearts,
Clubs,
Diamonds,
Spades
}
class Card
{
public Face Face { get; }
public Suit Suit { get; }
public Card(Face face, Suit suit)
{
this.Face = face;
this.Suit = suit;
}
public override string ToString()
{
return $"{Face} of {Suit}";
}
}
}