30 lines
620 B
JavaScript
30 lines
620 B
JavaScript
|
import {
|
||
|
Card
|
||
|
} from "./Card.js";
|
||
|
|
||
|
export class CardDeck {
|
||
|
constructor() {
|
||
|
this.cards = [];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns a random card of this deck
|
||
|
* @returns {Card}
|
||
|
*/
|
||
|
getRandomCard() {
|
||
|
return this.cards[Math.floor(Math.random() * this.cards.length)];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const cardDecks = [];
|
||
|
|
||
|
// Default card deck
|
||
|
const defaultDeck = new CardDeck();
|
||
|
const colors = ['RED', 'GREEN', 'BLUE', 'YELLOW'];
|
||
|
colors.forEach(color => {
|
||
|
for (let i = 0; i < 10; i++) {
|
||
|
defaultDeck.cards.push(new Card(color, i));
|
||
|
}
|
||
|
});
|
||
|
|
||
|
cardDecks.push(defaultDeck);
|