-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeck.pde
155 lines (122 loc) · 2.93 KB
/
Deck.pde
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
public class Deck extends Obj {
// * DRAWING CONSTANTS
final int x_deck = 200;
final int y_deck = 500;
int x_hand;
int y_hand = 500;
public LinkedList<Card> cards = new LinkedList();
public Card hand;
public PImage hand_img;
public final int flip_cycles_end = 5;
public int flipCycles = 0;
public int flipCycles_back = 0;
public final int cycles_next_round_end = 60;
public int cycles_next_round = 0;
public int hand_x_step;
public int hand_y_step;
/**
* Generates a deck then shuffles it
*/
public Deck(Assets a, Variables v) {
super(a, v);
for (int n = 2; n <= 14; n++) {
for (Suit s : Suit.values()) {
Card c = new Card(n, s);
cards.add(c);
}
}
// Shuffle the cards
Collections.shuffle(cards);
hand = cards.remove();
}
public String toString() {
return hand.toString();
}
/**
* Deals the top card to the player
*/
public void hardDeal(Player p) {
p.hand = cards.remove();
updateHandImg();
}
public void setup() {
x_hand = x_deck;
int dx = v.cw - x_deck ;
hand_x_step = dx / flip_cycles_end;
int dy = Player.y_hand - y_deck;
hand_y_step = dy / flip_cycles_end;
}
public void _update() {
if (v.nextRound) {
hardNextRound();
}
drawHand();
drawDeck();
if (v.hasVoted && !v.isFlippingHand) {
v.flip = true;
v.isFlippingHand = true;
}
}
protected void drawDeck() {
push();
// If cards are left in the deck
if (cards.size() > 0) {
image(a.back, x_deck, y_deck, Card.w, Card.h);
}
pop();
}
protected void drawHand() {
if (!v.flip) {
image(a.back, x_hand, y_hand, Card.w, Card.h);
} else {
// guh flip the thing
image(hand_img, x_hand, y_hand, Card.w, Card.h);
// Move the card
if (flipCycles != flip_cycles_end) {
x_hand += hand_x_step;
flipCycles++;
} else {
if (cycles_next_round != cycles_next_round_end) {
cycles_next_round++;
} else {
nextRound();
}
}
}
}
private void updateHandImg() {
hand_img = a.getCard(hand);
}
/**
* Should handle the case where this is the last round
*/
private void nextRound() {
if (flipCycles_back != flip_cycles_end) {
v.isFlippingHandBack = true;
flipCycles_back++;
y_hand += hand_y_step;
} else {
v.isFlippingHandBack = false;
v.nextRound = true;
}
}
/**
* Shold be called when the transitions are done
* Updates the palyers cards and resets all local variables
*/
private void hardNextRound() {
player.hand = hand;
hand = cards.remove();
updateHandImg();
v.flip = false;
v.isFlippingHand = false;
v.isFlippingHandBack = false;
v.hasVoted = false;
v.nextRound = false;
x_hand = x_deck;
y_hand = y_deck;
flipCycles = 0;
flipCycles_back = 0;
cycles_next_round = 0;
}
}