blackjack logic written in vue
https://luna-development.net/blackjack/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
913 B
52 lines
913 B
class Hand { |
|
cards; |
|
points; |
|
|
|
constructor() { |
|
this.cards = []; |
|
} |
|
|
|
static create() { |
|
return new Hand(); |
|
} |
|
|
|
static createDealerHand() { |
|
let dealerHand = new Hand(); |
|
dealerHand.isDealer = true; |
|
|
|
return dealerHand; |
|
} |
|
|
|
/** |
|
* Adds given Card to the hand |
|
* @param {Card} drawnCard |
|
*/ |
|
pickCard(drawnCard) { |
|
if (drawnCard.ace && this.points > 10) { |
|
drawnCard.points = 1; |
|
} |
|
|
|
this.cards.push(drawnCard); |
|
this.points = (this.points + drawnCard.points); |
|
} |
|
|
|
includesAces(hand) { |
|
let aceCount = 0; |
|
|
|
hand.forEach((card) => { |
|
if (card.ace === true) { |
|
aceCount++; |
|
} |
|
}); |
|
|
|
return aceCount; |
|
} |
|
|
|
hasBlackjack() { |
|
return this.points === 21; |
|
} |
|
|
|
isPlus() { |
|
return this.points > 21; |
|
} |
|
} |