This repository has been archived on 2021-10-15. You can view files and clone it, but cannot push or open issues or pull requests.
2020-coding-projects/uno/client/Stack.js

31 lines
728 B
JavaScript
Raw Normal View History

2020-05-05 20:35:48 +00:00
export class Stack {
constructor() {
this.cards = [];
}
allows(card) {
return card.color === 'BLACK' || this.cards.length === 0 || this.cards[this.cards.length - 1].allows(card);
}
add(card) {
this.cards.push(card);
if (this.cards.length > 5) {
this.cards.splice(0, 1);
}
return true;
}
setTopColor(color) {
this.cards[this.cards.length - 1].actualColor = color;
}
draw(renderer) {
if (this.cards.length === 0) {
return;
}
for (let i = 0; i < 5 && i < this.cards.length; i++) {
this.cards[i].draw(renderer, -i * 6, -i * 6);
}
}
}