diff --git a/game-logic.js b/game-logic.js index 5ada93288740942463b6ac55885a091b31cde550..c074d3d21aa69b5cfbc62d181133b93a32b14200 100644 --- a/game-logic.js +++ b/game-logic.js @@ -1,6 +1,7 @@ const gameState = { playerWallet: 100, - currentBet: null + currentBet: null, + cards: [[], []] } function collectBet(){ @@ -22,10 +23,26 @@ function collectBet(){ return currentBet; } +function drawCard(){ + let min = 2; + let max = 11; + let rndNum = min + Math.floor(Math.random()*(max - min + 1 )); + + return rndNum; +} + function blackjack(){ // decide the bet, collect it gameState.currentBet = collectBet(); + for(let playerIndex = 0; playerIndex < gameState.cards.length; playerIndex++){ + for(let cardIndex = 0; cardIndex < 2; cardIndex++){ + gameState.cards[playerIndex][cardIndex] = drawCard(); + } + } + + console.log(gameState.cards); + // we deal the first 2 cards for the player // check immediately that the player has blackjack // if so, we need to pay 2.5 the bet -> end the game