-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardDeck.cs
60 lines (57 loc) · 1.45 KB
/
CardDeck.cs
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
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class CardDeck
{
public int numCard = 52;
private Card[] deck;
private int numCards;
public CardDeck()
{ deck = new Card[52];
fill();
}
public void shuffle()
{
for (int next = 0; next < numCards - 1; next++)
{
Random rnd = new Random();
int r = rnd.Next(next, numCards - 1);
Card temp = deck[next];
deck[next] = deck[r];
deck[r] = temp;
}
}
public Card deal()
{
if (numCards == 0) return null;
numCards--; return deck[numCards];
}
public int getSize()
{
return numCards;
}
private void fill()
{
int index = 0;
for (int r = 1; r <= 13; r++)
{
for (int s = 1; s <= 4; s++)
{
deck[index] = new Card(r, s);
index++;
}
}
numCards = 52;
}
private static int myRandom(int low, int high)
{
Random rnd = new Random();
int n = rnd.Next();
return (int)((high + 1 - low) * n + low);
}
}
}