forked from prmr/SoftwareDesign
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiDeck.java
More file actions
64 lines (60 loc) · 1.17 KB
/
MultiDeck.java
File metadata and controls
64 lines (60 loc) · 1.17 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
56
57
58
59
60
61
62
63
64
package comp303;
/**
* A class that represents a deck of cards composed of multiple decks
* of cards. This version does not implement the copy-constructor
* part the exercise.
*
* @author Martin P. Robillard
*/
public class MultiDeck
{
private Deck[] aDecks;
/**
* Creates an initialized, shuffled multi-deck from pNumberOfDecks
* decks.
* @param pNumberOfDecks The number of decks in the multi-deck
* @pre pNumberOfDecks > 0
*/
public MultiDeck(int pNumberOfDecks)
{
assert pNumberOfDecks > 0;
aDecks = new Deck[pNumberOfDecks];
for( int i =0; i < aDecks.length; i++ )
{
aDecks[i] = new Deck();
aDecks[i].shuffle();
}
}
/**
* @return The next card in the multi-deck
* @pre !isEmpty()
*/
public Card draw()
{
assert !isEmpty();
for( Deck deck : aDecks )
{
if( deck.isEmpty() )
{
continue;
}
return deck.draw();
}
assert false;
return null;
}
/**
* @return True if all decks in this multi-deck are empty
*/
public boolean isEmpty()
{
for( Deck deck : aDecks )
{
if( !deck.isEmpty() )
{
return false;
}
}
return true;
}
}