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.
85 lines
2.3 KiB
85 lines
2.3 KiB
class Blackjack { |
|
deck; |
|
bank; |
|
bet; |
|
roundActive = false; |
|
vue; |
|
|
|
constructor(vue) { |
|
this.vue = new Vue(); |
|
this.deck = CardDeck.createAndShuffle(vue); |
|
this.bank = LunaBank.createEmpty(); |
|
// this.bank = new LunaBank(vue); |
|
|
|
this.dealer = Hand.createDealerHand(); |
|
this.player = Hand.create(); |
|
} |
|
|
|
startRound() { |
|
if (this.bet > this.bank.money) { |
|
alertify.notify('Not enough money for bet.'); |
|
this.endRound(); |
|
} |
|
|
|
this.bank.money -= this.bet; |
|
this.roundActive = true; |
|
|
|
this.player.pickCard(this.deck.takeOneCard()); |
|
this.dealer.pickCard(this.deck.takeOneCard()); |
|
this.player.pickCard(this.deck.takeOneCard()); |
|
this.dealer.pickCard(this.deck.takeOneCard()); |
|
|
|
if (this.dealer.hasBlackjack()) { |
|
this.dealer.win(); |
|
} |
|
|
|
if (this.player.points === 21) { |
|
this.player.pass(); |
|
} |
|
|
|
console.log('Round has started'); |
|
} |
|
|
|
pass() { |
|
if (this.dealer.points === this.player.points) { |
|
this.roundActive = false; |
|
alertify.notify('Draw!'); |
|
this.draw(); |
|
} else if (this.dealer.points > 21) { |
|
this.roundActive = false; |
|
alertify.notify('Dealer is plus, you win'); |
|
this.win(); |
|
} else if (this.dealer.points > this.player.points) { |
|
this.roundActive = false; |
|
alertify.notify('Dealer Wins'); |
|
} else if (this.dealer.points < 17) { |
|
this.roundActive = false; |
|
this.dealer.pickCard(this.deck.takeOneCard()); |
|
this.pass(); |
|
} else if (this.player.points > this.dealer.points && this.player.points < 22) { |
|
this.roundActive = false; |
|
alertify.notify('You win ' + this.bet * 1.5 + '!'); |
|
this.win(); |
|
} |
|
} |
|
|
|
draw() { |
|
this.money = (parseInt(this.money) + parseInt(this.bet)); |
|
} |
|
|
|
win() { |
|
this.money += (parseInt(this.bet) * 2); |
|
} |
|
|
|
endRound() { |
|
this.roundActive = false; |
|
this.lastCard = null; |
|
this.status = null; |
|
this.dealersHand = []; |
|
this.dealer.points = 0; |
|
this.usersHand = []; |
|
this.player.points = 0; |
|
|
|
this.deck = CardDeck.createAndShuffle(); |
|
} |
|
} |