From 2bebaeb5b6dd049400763606c19b98716bfdb6f8 Mon Sep 17 00:00:00 2001 From: Jonathan Vitale <jvitale@une.edu.au> Date: Thu, 17 Nov 2022 14:02:34 +1100 Subject: [PATCH] Add code for tutorial 3 --- game-logic.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/game-logic.js b/game-logic.js index 5ada932..c074d3d 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 -- GitLab