
8 changed files with 136 additions and 3 deletions
@ -1,2 +1,2 @@ |
|||||||
- [x] #001 dealer wins 22v20 |
- [x] #001 dealer wins 22v20 |
||||||
- [ ] #002 draw uses strings to payout |
- [x] #002 draw uses strings to payout |
@ -0,0 +1,8 @@ |
|||||||
|
class Blackjack { |
||||||
|
deck; |
||||||
|
bank; |
||||||
|
|
||||||
|
constructor() { |
||||||
|
this.bank = new LunaBank(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
class Card { |
||||||
|
color; |
||||||
|
symbol; |
||||||
|
points; |
||||||
|
ace = false; |
||||||
|
assetUrl; |
||||||
|
|
||||||
|
constructor(color, symbol, points, ace, assetBaseUrl = 'img/') { |
||||||
|
this.color = color; |
||||||
|
this.symbol = symbol; |
||||||
|
this.points = points; |
||||||
|
this.ace = ace; |
||||||
|
this.assetUrl = this.createAssetPath(assetBaseUrl); |
||||||
|
} |
||||||
|
|
||||||
|
createAssetPath(assetBaseUrl) { |
||||||
|
return assetBaseUrl + this.color + this.symbol + '.png' |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,99 @@ |
|||||||
|
class CardDeck { |
||||||
|
constructor() { |
||||||
|
this.generateDeck(); |
||||||
|
} |
||||||
|
|
||||||
|
create() { |
||||||
|
return new CardDeck(); |
||||||
|
} |
||||||
|
|
||||||
|
createAndShuffle() { |
||||||
|
let cardDeck = new CardDeck(); |
||||||
|
cardDeck.shuffle(); |
||||||
|
|
||||||
|
return cardDeck; |
||||||
|
} |
||||||
|
|
||||||
|
generateDeck() { |
||||||
|
const colors = ['spades', 'clubs', 'diamonds', 'hearts']; |
||||||
|
const highCards = ['j', 'q', 'k']; |
||||||
|
|
||||||
|
let cardDeck = []; |
||||||
|
|
||||||
|
colors.forEach((color) => { |
||||||
|
for (let cardPoints = 1; cardPoints <= 10; cardPoints++) { |
||||||
|
let symbol = cardPoints; |
||||||
|
let points = cardPoints; |
||||||
|
let isAnAce = false; |
||||||
|
|
||||||
|
if (cardPoints === 1) { |
||||||
|
points = 11; |
||||||
|
symbol = 'a'; |
||||||
|
isAnAce = true; |
||||||
|
} |
||||||
|
|
||||||
|
let card = new Card( |
||||||
|
color, |
||||||
|
symbol, |
||||||
|
points, |
||||||
|
isAnAce |
||||||
|
) |
||||||
|
|
||||||
|
cardDeck.push(card); |
||||||
|
} |
||||||
|
|
||||||
|
highCards.forEach((highCard) => { |
||||||
|
let card = new Card( |
||||||
|
color, |
||||||
|
highCard, |
||||||
|
10, |
||||||
|
false |
||||||
|
) |
||||||
|
|
||||||
|
cardDeck.push(card); |
||||||
|
}); |
||||||
|
|
||||||
|
this.deck = cardDeck; |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
shuffle(runs = 1) { |
||||||
|
let cardCount = this.deck.length, t, i; |
||||||
|
|
||||||
|
for (let run = 0; run === runs; run++) { |
||||||
|
while (cardCount) { |
||||||
|
i = Math.floor(Math.random() * cardCount--); |
||||||
|
t = this.deck[cardCount]; |
||||||
|
this.deck[cardCount] = this.deck[i]; |
||||||
|
this.deck[i] = t; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
cardsInStack() { |
||||||
|
return this.deck.length; |
||||||
|
} |
||||||
|
|
||||||
|
deckIsEmpty() { |
||||||
|
return this.deck.length > 0 ? true : false; |
||||||
|
} |
||||||
|
|
||||||
|
takeOneCard(cardsToDraw = 1) { |
||||||
|
if (this.cardsInStack() > 0) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
return this.deck.shift(); |
||||||
|
} |
||||||
|
|
||||||
|
takeCards(cardsToDraw) { |
||||||
|
let drawnCards = []; |
||||||
|
|
||||||
|
for (let run = 0; run === cardsToDraw; run++) { |
||||||
|
drawnCards.push(this.deck.shift()); |
||||||
|
} |
||||||
|
|
||||||
|
return drawnCards; |
||||||
|
} |
||||||
|
} |
||||||
|
|
Binary file not shown.
Loading…
Reference in new issue