move card pile to own file

trunk
vilmibm 2020-11-24 20:23:06 -08:00
parent d4145a9797
commit 5e990df0d6
2 changed files with 40 additions and 39 deletions

39
cardpile.js 100644
View File

@ -0,0 +1,39 @@
class CardPile {
constructor() {
this.cards = new Set();
}
add(cardName) {
this.cards.add(cardName);
}
has(cardName) {
return this.cards.has(cardName);
}
get size() {
return this.cards.size;
}
drawRandom() {
const size = this.cards.size
if (size === 0) {
return null;
}
const index = Math.floor(Math.random() * Math.floor(size));
let i = 0;
let cardName = "";
for (let card of this.cards) {
if (i === index) {
cardName = card;
break
}
i++;
}
this.cards.delete(cardName);
return cardName;
}
}
export default CardPile;

View File

@ -1,6 +1,5 @@
import cardDB from './cards.js';
// TODO reset state button
import CardPile from './cardpile.js';
class Tarot {
constructor() {
@ -130,42 +129,5 @@ class Renderer {
}
}
class CardPile {
constructor() {
this.cards = new Set();
}
add(cardName) {
this.cards.add(cardName);
}
has(cardName) {
return this.cards.has(cardName);
}
get size() {
return this.cards.size;
}
drawRandom() {
const size = this.cards.size
if (size === 0) {
return null;
}
const index = Math.floor(Math.random() * Math.floor(size));
let i = 0;
let cardName = "";
for (let card of this.cards) {
if (i === index) {
cardName = card;
break
}
i++;
}
this.cards.delete(cardName);
return cardName;
}
}
export default Tarot;