Mike's Blackjack Game

by Mike Arends

HTML

<div id="game-window">

        <h1>Blackjack Game!</h1>
        <div id="game-wrapper">
            <div id="game-message" class="hide-element">Game Message</div>
            <button id="start-game">Start Game</button>
            <div id="dealer">
                <div id="dealer-hand-value"></div>
                <div id="dealer-card-container" class="playingCards faceImages">
                    <ul id="dealer-table" class="table clear-fix">
                        <div class="card hide-element"></div>
                    </ul>
                </div>
            </div>
            <div id="player">
                <div id="player-card-container" class="playingCards faceImages">
                    <ul id="player-table" class="table clear-fix">
                        <div class="card hide-element"></div>
                    </ul>
                </div>
                <div class="hand-value"></div>
                <div id="player-cash" class="remove-element"></div>
                <div id="current-bet" class="remove-element"></div>
                <div id="player-buttons" class="remove-element">
                    <div id="action-bar">
                        <div id="betting">
                            <p id="bet-text">Place your bet (Max $250)</p>
                            <div id="bet-controls">
                                <button class="bet" id="bet-1">$1</button>
                                <button class="bet" id="bet-5">$5</button>
                                <button class="bet" id="bet-10">$10</button>
                                <button class="bet" id="bet-100">$100</button>
                                <button class="bet" id="bet-clear">Clear Bet</button>
                                <button class="bet" id="bet-complete">Deal</button>
                            </div>
                        </div>
                        <div id="player-actions" class="remove-element">
                            <div...

CSS

/**
 * Styles for CSS Playing Cards
 *
 * @author   Anika Henke <anika@selfthinker.org>
 * @license  CC BY-SA [http://creativecommons.org/licenses/by-sa/3.0]
 * @version  2011-06-14
 * @link     http://selfthinker.github.com/CSS-Playing-Cards/
 */

/* card itself
********************************************************************/

.playingCards .card {
    display: inline-block;
    width: 3.3em;
    height: 4.6em;
    border: 1px solid #666;
    border-radius: .3em;
    -moz-border-radius: .3em;
    -webkit-border-radius: .3em;
    -khtml-border-radius: .3em;
    padding: .25em;
    margin: 0 .5em .5em 0;
    text-align: center;
    font-size: 1.2em; /* @change: adjust this value to make bigger or smaller cards */
    font-weight: normal;
    font-family: Arial, sans-serif;
    position: relative;
    background-color: #fff;
    -moz-box-shadow: .2em .2em .5em #333;
    -webkit-box-shadow: .2em .2em .5em #333;
    box-shadow: .2em .2em .5em #333;
}

.playingCards a.card {
    text-decoration: none;
}
/* selected and hover state */
.playingCards a.card:hover, .playingCards a.card:active, .playingCards a.card:focus,
.playingCards label.card:hover,
.playingCards strong .card {
    bottom: 1em;
}
.playingCards label.card {
    cursor: pointer;
}

.playingCards .card.back {
    text-indent: -4000px;
    background-color: #ccc;
    background-repeat: repeat;
    background-image: url(data:image/gif;base64,R0lGODlhJAAkAJEAAOjFsezdztOKbL5QKCH5BAAAAAAALAAAAAAkACQAAAL/HC4RAqm/mmLHyHmAbczB11Ea8ombJKSgKo6Z17pXFznmS1JptiX0z3vVhpEKDoUIkoa0olGIUeZUk1RI6Yn2mh/FDAt6frOrRRTqXPpsVLYugzxaVy+YcBdnoWPZOT0E4eckQtZFZBjWoHixQFWl6Nhol6R2p1Okt5TGaEWZA6fjiMdhZgPHeWrTWGVq+jTZg1HYyAEWKLYzmyiGKoUimilz+YYryyTlg5RcDJSAbNx0Q7lMcbIGEyzTK8zVdfVaImzs/QV+prYqWWW2ObkoOApM/Em/rUlIm7fijs8a2EEKEaZ3AsMUgneEU6RcpJbZ27aGHkAO2Ors8xQH1IR0Bn5YnOtVAAA7); /* image is "Pattern 069" from http://www.squidfingers.com/patterns/ */
    background-image: -moz-repeating-linear-gradient(34% 6% 135deg,#0F1E59, #75A1BF,...

JavaScript

function GameControl()
{
    this.currentBetElement = document.getElementById('current-bet');
    this.playerCash = document.getElementById('player-cash');
    this.currentBet = document.getElementById('current-bet');
    this.placeBetText = document.getElementById('bet-text');
    this.betElement = document.getElementById('bet-controls');
    this.clearBet = document.getElementById('bet-clear');
    this.betComplete = document.getElementById('bet-complete');
    this.betOne = document.getElementById('bet-1');
    this.betFive = document.getElementById('bet-5');
    this.betTen = document.getElementById('bet-10');
    this.betHundred = document.getElementById('bet-100');
    this.startGame = document.getElementById('start-game');
    this.playerButtons = document.getElementById('player-buttons');
    this.handValueElement = document.getElementById('hand-value');
    this.dealerHandValueElement = document.getElementById('dealer-hand-value');
    this.playerActions = document.getElementById('player-actions');
    this.gameMessage = document.getElementById('game-message');
    this.playerElement = document.getElementById('player');
    this.dealerElement = document.getElementById('dealer');
    this.waitingForInsuranceAnswer = false;
    this.doubleDownThisTurn = false;
    this.isGameOver = false;
}

GameControl.prototype.blackJackWinControl = function()
{
    if(dealer.hasBlackjack && !player.hasBlackjack)
    {
        console.log('In Win Control and Dealer has Blackjack');
        game.displayBannerMessage('Dealer has Blackjack!');
        if(player.takesInsurance)
        {
            //Pays Insurance back to player because winnings are equal to the bet
            player.cash += player.betValue;
        }
        game.renderCards(dealer, true);

    }else if(!dealer.hasBlackjack && player.hasBlackjack)
    {
        game.displayBannerMessage('Player has Blackjack!  Player wins ')
    }
    else if(dealer.hasBlackjack && player.hasBlackjack)
    {
       ...