-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeck.js
34 lines (29 loc) · 837 Bytes
/
deck.js
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
class Deck {
constructor(){
this.deck;
this.build();
}
build(){
const values = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
const types = ["C", "D", "H", "S"];
this.deck = [];
for (let i = 0; i < types.length; i++) {
for (let j = 0; j < values.length; j++) {
const card = new Card(values[j], types[i]);
this.deck.push(card);
}
}
this.shuffle();
}
shuffle(){
for(let i = 0; i < this.deck.length; i++){
let rand = Math.floor(Math.random() * this.deck.length);
let temp = this.deck[i];
this.deck[i] = this.deck[rand];
this.deck[rand] = temp;
}
}
pop(){
return this.deck.pop();
}
}