Lesson 26. Capstone: Blackjack

 

In this capstone you’re going to build a Blackjack (21) game like the one shown in figure 26.1.

Figure 26.1. A Blackjack game

A game of cards has many sets. A deck is a set of cards and each player’s hand is also a set of cards. You’ll also make use of maps and eventually use a generator to create a function that slows down the looping of an iterator so that it can be animated on the screen.

Note

You’ll start your project using the start folder included in the code accompanying this book. If at any time you get stuck, you can also check out the final folder with the completed game. The start folder is a project already set up to use Babel and Browserify (see lessons 13); you just need to run npm install to get set up. If you haven’t read unit 0, you should before doing this capstone. There’s also an included index.html file: this is where the game will run. It already includes all the HTML and CSS it needs; you just need to open it in a browser once you bundle your JavaScript files. The src folder is where you’ll put all your JavaScript files; there are a couple already included. The dest folder is where the bundled JavaScript file will go after you run npm run build. You’ll need to remember to run npm run build to compile your code anytime you make a change.

26.1. The cards and the deck

26.2. Making the CPU’s turn slow enough to see

26.3. Putting the pieces together

Summary