Here is a quick BlackJack game implementation for two players (user and computer) in JavaScript using the Underscore library, some Bootstrap and JS Minifier.
The goal is to reach 21 points or at least stay as close as possible to that score. Starts Player 1 who receives as many cards as user wants by clicking on the "New card" button. As well, the player can stop his game through the "Stop" button which will mean is passing the turn to the computer.
-
Building out the 52 card deck automatically associating images to values and figures.
-
Shuffling the deck so that in each new game they have a different order.
-
Create the 2 players. For each player I keep track its "id" and their current score.
-
Check for winner evaluates whether any of the players has reached, approaches or exceeds 21 points. It compares the scores of both players and determines who wins, loses or if there is a tie.
-
Modal. Depending on the winner shows a modal window with a specific message and emoji for it. Also changes the color of the score on the mat all modifying the DOM.
-
Refactor code.
-
Create a Module Pattern to encapsulate all the application logic of the game and make all the variables and functions only be visible inside the module.
- HTML5
- CSS3
- Bootstrap
- JavaScript
- Underscore
This is the first time I use the Underscore library and a Pattern Module.
- GitHub: https://github.com/albavidalm
- Email: albavidalm @ gmail.com
- Linkedin: https://www.linkedin.com/in/albavidalm/
Sharing is caring, contributions and suggestions are always welcome.