I'm working on a blackjack game for fun, I'm having a problem adding the cards though. What would I do to add the last card to a score that was put down?
It's not a complete game yet, its just a project and please don't bash my code lol
Code:
<html>
<head>
<style type="text/css">
#playing_area{
height: 400px;
width: 600px;
position: relative;
border: 1px solid black;
background-color: #088A4B;
}
#dealer_area{
border: 1px solid black;
}
#player_area{
}
.card{
height: 60px;
width: 40px;
background-color: white;
border: 1px solid black;
float: left;
-moz-border-radius: 10px 10px;
border-radius: 10px 10px;
padding: 5px;
box-shadow: 5px 5px 5px;
-moz-box-shadow: 5px 5px 5px;
}
</style>
</head>
<body>
<div id="playing_area">
<button id="start">Start Game</button>
<div id="dealer_area">
<h3 style="text-align: center;">Dealer</h3>
<div id="dealer_cards"></div>
<div id="dealer_score"></div>
</div>
<div id="player_area"></div>
</div>
<script type="text/javascript">
var start=document.getElementById('start');
var dealer=document.getElementById('dealer_area');
var dealerCards=document.getElementById('dealer_cards');
var dealerScore = document.getElementById('dealer_score');
var i;
var score=0;
//declare the array of the deck of cards
var deck = new Array();
deck[0]=1;
deck[1]=2;
deck[2]=3;
deck[3]=4;
deck[4]=5;
deck[5]=6;
deck[6]=7;
deck[7]=8;
deck[8]=9;
deck[9]=10;
deck[10]=11;
deck[11]=12;
function gamestart(){
var i= Math.round( Math.random(i)*11);
var newCard = document.createElement('div');
var card=dealerCards.appendChild(newCard);
card.innerHTML = deck[i];
card.setAttribute('class','card');
}
start.setAttribute('onclick', 'gamestart()');
</script>
</body>
</html>
i figured out a way to add them up, but you will need to do something if bust/win/lose.
maybe you can use some of the parts below in your code, like the suite 'icons', or the scoring routine, help yourself to whatev.
But I don't think your code will do. The thing with your code is that you rewrote my whole code and it's far to complicated which i don't think it should be to add a few simple cards.
You have no protection in your code to stop the system from, for example, dealing 7 aces of spades in a row.
You need to create a full deck (including suits) and then decide on how many decks the dealer will deal from (nobody in Nevada deals from one deck...typically there are 4 or more decks in the "shoe").
I agree that RndMe's code is more complex than you probably need/are looking for, but yours is way too simplistic.
Just as a for instance: If somebody has an Ace and a 6 (for 17 points) and draws a 7, will you be smart enough to convert the Ace to 1 point and make the total now by 14, instead of 24?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
I know that, like I said in the initial post, no where near done. Basically it's not even blackjack yet, it's jut 21. I figured out a way how to make it add up the amounts, but I need to make it build dynamically.