-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDeck.java
More file actions
55 lines (48 loc) · 1.14 KB
/
Copy pathDeck.java
File metadata and controls
55 lines (48 loc) · 1.14 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
54
55
package com.polymars.game;
import java.util.ArrayList;
import java.util.Random;
public class Deck {
private final ArrayList<Card> deck;
Random rand = new Random();
public Deck()
{
deck = new ArrayList<Card>();
}
public void createCards()
{
for (int value = 2; value <= 12; value++)
{
for (int element = Cards.FIRE; element <= Cards.SNOW; element++)
{
int color = rand.nextInt(Cards.PURPLE + 1);
Card card = new Card(element, value, color);
deck.add(card);
}
}
shuffle();
}
public ArrayList<Card> getCards()
{
return deck;
}
public Card deal()
{
Card card = deck.remove(0);
if (deck.isEmpty())
{
createCards();
}
return card;
}
public void shuffle()
{
for (int i = 0; i < deck.size(); i++)
{
int index = rand.nextInt(deck.size());
Card x = deck.get(i);
Card y = deck.get(index);
deck.set(i, y);
deck.set(index, x);
}
}
}