HTML and CSS Reference
In-Depth Information
Code
Explanation
</body>
Closes the body
</html>
Closes the HTML file
You can change the look and feel of this game in many ways, including offering different ways for the
player to request to be dealt a new card, to hold with the current hand, or to request a new hand. You can
create or acquire your own set of card images. Keeping score from hand to hand, perhaps including some
kind of betting, would be a fine enhancement. Changing the rules for the dealers play is possible.
Testing and uploading the application
This program requires considerable testing. Remember that the testing is not finished when you, acting as
tester, have won. It is finished when you have gone through many different scenarios. I did my first testing
of the game with an unshuffled deck. I then put in the shuffling and kept track of the cases that the testing
revealed. I pressed the d key for dealing one more card, the h for holding, and the n for a new game in
different circumstances. This is definitely a situation when you want to bring in other people to test your
application.
Uploading the application requires uploading all the images. You will need to change the builddeck
function to construct the appropriate names for the files if you use something different than what I
demonstrate here.
Summary
In this chapter, you learned how to implement a card game using features of HTML5, JavaScript, and CSS
along with general programming techniques. These included
Generating a set of Image objects based on names of external files
Designing a programmer-defined object for cards, incorporating the Image s
Drawing images and text on the screen
Making use of for , while , and if to implement the logic of blackjack
Using calculations and logic to generate the computer's moves
Establishing event handling for the keydown event so that the player could indicate a request
to deal a new card, hold, or start a new game and using switch to distinguish between the
keys
Using the header and footer elements, new to HTML5, for directions and giving credit to
sources
This is the last chapter of this topic. I hope you take what you have learned and produce enhanced
versions of these games and games of your own invention. Enjoy!
 
Search WWH ::




Custom Search