-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeck.java
More file actions
118 lines (81 loc) · 2.19 KB
/
Copy pathdeck.java
File metadata and controls
118 lines (81 loc) · 2.19 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.Collections;
public class deck {
private repertoir_card repertoir;
private Stack<card> drawpile;
private Stack<card> discardpile;
private card top;
public deck() {
repertoir = new repertoir_card();
drawpile = new Stack<>();
discardpile = new Stack<>();
drawpile = initDeck();
discardpile = initDISCARD();
}
// crrer pile draw
public Stack<card> initDeck(){
List<card> Deck = new ArrayList<card>();
Stack<card> pile = new Stack<>();
Deck = repertoir.initCard();
Collections.shuffle(Deck);
for (card cd : Deck)
{
pile.push(cd);
}
return pile;
}
public card drawplus(int n){//n c le nmbr de cartes a piocher
for (int i=0;i<n;i++){
if (drawpile.isEmpty()) {
refile();
}
return(drawpile.pop());
// ajouter carte a la main du joueur
}
return null;
}
//creer pile discard
public Stack<card> initDISCARD(){
// faut prendre en compte que card = sizeof drawpile- n*7
Stack<card> pile = new Stack<card>();
//discardpile.push(drawpile.pop());
return pile;
// retourne le stack
}
// quand pile draw empty
public void refile(){
if (drawpile.isEmpty() ){
top=discardpile.pop();// sauvegarder la carte du dessus de discard pile
List<card> deck =new ArrayList<card>();
while (!discardpile.isEmpty()){// vider la discard pile
deck.add(discardpile.pop());
}
Collections.shuffle(deck);// melanger les cartes
for(card carte:deck){
if (carte instanceof nonregular){
if (((nonregular)carte).gettype() == type.wild || ((nonregular)carte).gettype() == type.wild_4_plus){
((nonregular)carte).setColor(color.WILD);
}
}
drawpile.push(carte);
}
discardpile.push(top);// remettre le top dans discard pile pour continuer le jeu
}
}
public card addtodraw(card card){
drawpile.push(card);
return card;
}
public card addtodiscard(card card){
discardpile.push(card);
return card;
}
public void removefromdraw(card card){
drawpile.pop();
}
public card getTopDiscard() {
return discardpile.peek();
}
}