The Essential Guide to HTML5

(Greg DeLong) #1

BLACKJACK


339

Code Explanation


} Close the while loop


if (ch>=51) { Asks if there were no undealt cards


ctx.fillText("NO MORE CARDS IN
DECK. Reload. ",200,250);


Displays a message

ch = 51; Sets ch to 51 to make this function
work


} Closes the if-true clause


deck[ch].dealt = who; Stores who, a nonzero value, so this
card is marked as having been dealt


card = deck[ch]; Sets a card


return card; Returns a card


} Closes the function


function builddeck() { Header for the function that builds
the MCard objects


var n; Variable used for inner iteration


var si; Variable used for outer iteration,
over the suits


var suitnames= ["clubs","hearts",
"spades","diamonds"];


Names of suits

var i; Keeps track of elements put into the
deck array


i=0; Initializes the array to 0


var picname; Simplifies the coding


var nums=["a","2","3","4","5","6","7",
"8","9","10","j","q","k"];


The names for all the cards

for (si=0;si<4;si++) { Iterates over the suits


x
Free download pdf