HTML and CSS Reference
In-Depth Information
(punctuation) for referencing an attribute of an MCard object when the object is an element of an array is
playerhand[pi].picture .
The dealstart function has the task of dealing the first four cards: two to the player and two to the
dealer. One of the dealers cards is not shown; that is, the cards back is shown. The deal function is
invoked when the player requests a new card (see later in this section). The deal function will deal a card
to the player and see if the dealer is to get a new card. Both dealstart and deal accomplish the actual
dealing by invoking the dealfromdeck function, adding the cards to the playerhand and househand
arrays and drawing the cards on the canvas. Formally, the dealfromdeck is a function that returns a
value of type MCard . Its call appears on the right side of assignment statements. If the face of the card is
to show, the Image object drawn is the one referenced by the card. If the back of the card is to show, the
Image object is the one held in the variable back .
Here is the dealstart function. Notice the four similar sets of statements: get the card, draw the image,
increment the x position for the next time, and increase indexing variable, pi or hi .
function dealstart() {
playerhand[pi] = dealfromdeck(1);
ctx.drawImage(playerhand[pi].picture,playerxp,playeryp,cardw,cardh);
playerxp = playerxp+30;
pi++;
househand[hi] = dealfromdeck(2);
ctx.drawImage(back,housexp,houseyp,cardw,cardh);
housexp = housexp+20;
hi++;
playerhand[pi] = dealfromdeck(1);
ctx.drawImage(playerhand[pi].picture,playerxp,playeryp,cardw,cardh);
playerxp = playerxp+30;
pi++;
househand[hi] = dealfromdeck(2);
ctx.drawImage(househand[hi].picture,housexp,houseyp,cardw,cardh);
housexp = housexp+20;
hi++;
}
The deal function is similar. A card is added to the player's hand and to the house if more_to_house
returns true .
function deal() {
playerhand[pi] = dealfromdeck(1);
ctx.drawImage(playerhand[pi].picture,playerxp,playeryp,cardw,cardh);
playerxp = playerxp+30;
pi++;
if (more_to_house()) {
househand[hi] = dealfromdeck(2);
ctx.drawImage(househand[hi].picture,housexp,houseyp,cardw,cardh);
housexp = housexp+20;
hi++;
}
}
 
Search WWH ::




Custom Search