-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
34 lines (28 loc) · 1.01 KB
/
game.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 Game {
constructor() {
this.deck = {}
this.piles = {}
}
async draw(numCards) {
return await fetch(`https://deckofcardsapi.com/api/deck/${this.deck.deck_id}/draw/?count=${numCards}`)
.then(response => response.json())
}
async shuffle() {
this.deck = await fetch("https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1")
.then(response => response.json())
}
async getPile(name) {
return await fetch(`https://deckofcardsapi.com/api/deck/${this.deck.deck_id}/pile/${name}/list/`)
.then(response => response.json())
.then(data => data.piles[name])
}
async reshuffle(remaining) {
fetch(`https://deckofcardsapi.com/api/deck/${this.deck.deck_id}/shuffle/?remaining=${remaining}`)
}
async addToPile(name, cards) {
fetch (
`https://deckofcardsapi.com/api/deck/${this.deck.deck_id}/pile/${name}/add/?cards=${cards.join(',')}`
)
}
}
module.exports = Game;