-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.cs
More file actions
53 lines (47 loc) · 1.31 KB
/
Copy pathDeck.cs
File metadata and controls
53 lines (47 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
namespace blackjack
{
public class Deck
{
public List<Card> Cards = new List<Card>();
string[] Suits = {"Hearts", "Diamonds", "Spades", "Clubs"};
string[] FaceCards = {"Jack", "Queen", "King"};
public Deck() {
Create();
}
public void Create()
{
Cards.Clear();
foreach (var Suit in Suits)
{
Cards.Add(new Card("Ace", Suit, 11));
for (int i = 2; i < 11; i++)
{
Cards.Add(new Card(i.ToString(), Suit, i));
}
foreach (var FaceCard in FaceCards)
{
Cards.Add(new Card(FaceCard, Suit, 10));
}
}
}
public void Shuffle()
{
var newOrder = new List<Card>();
while (Cards.Count > 0)
{
int index = new Random().Next(Cards.Count);
newOrder.Add(Cards[index]);
Cards.RemoveAt(index);
}
Cards = newOrder;
}
public List<Card> Deal(int num)
{
var cards = Cards.GetRange(0, num);
Cards.RemoveRange(0, num);
return cards;
}
}
}