HTML and CSS Reference
In-Depth Information
Chapter 10
Blackjack
In this chapter, we will be covering
the footer and header tags, which are new to HTML5
capturing key presses
programmer-defined objects
generating Image elements using a set of external image files
shuffling a deck of cards
Introduction
The objective of this chapter is to combine programming techniques and HTML5 and JavaScript features
to implement the card game blackjack, also called 21. The implementation will make use of new tags
introduced in HTML5, namely footer and header . We will make use of the footer to give credit to the
source for the card images and the web site we are using for the shuffling algorithm. The cards are created
using programmer-defined objects and Image objects, with coding to generate the names of the image
files. The player makes moves using key presses.
The rules of blackjack are as follows: The player plays against the dealer (also known as the house). The
player and dealer are each dealt two cards. The first card of the dealer is hidden from the player, but the
other is visible. The value of a card is its face value for the numbered cards, 10 for a jack, queen, or king,
and either 1 or 11 for an ace. The value of a hand is the sum of the cards. The object of the game is to have
a hand with a value as close to 21 as possible without going over and to have a value greater than the
other person. Thus an ace and a face card count as 21, a winning hand. The actions are to request
another card or to hold.
Since this is a two-person game, our player will play against the computer, and as was the case with rock,
paper, scissors, we have the task of generating the computer moves. However, we are guided by the
practice of casinos—the dealer (house) will use a fixed strategy. Our dealer will request another card if the
value of the hand is under 17 (the game strategy in casinos may be slightly more complicated and may be
 
Search WWH ::




Custom Search