...

View Full Version : Blackjack Scoring



pdiddles03
10-02-2012, 05:11 PM
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



<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>

rnd me
10-02-2012, 07:05 PM
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.


<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>blackjack or whatev</title>
<style>
html, body { margin: 0; padding: 0; background: aliceblue; font-family: monospace; font-size: 20px; }
textarea { width: 47.5%; float: left; margin: 1%; }

#IN{display: none;} #OUT{display: inline-block;} #BUTTON{display: inline-block;}
</style> <link rel="icon" href="http://danml.com/sandbox/sandbox.png" type="image/x-icon">
</head>
<body onload='main()' id="body">
<h1>blackjack or whatev</h1>

<button id="BUTTON" onclick="main()"> Draw </button>


<br />

<label class='box'><b class='title'></b>
<textarea class="textbox" rows="35" name="IN" id="IN" cols="80" onchange="IN.title=IN.value.length+' Bytes.';return true; " tabindex="1" >

//this is the blackjack code to play with:

var suites=unescape("♦♥♠♣").split("");



Game={
score: 0,
drawn: 0,
hand: [],
draw: function drawOne(){
var card=Game.deck.pop();
Game.drawn++;
Game.score=Game.score + ((card.slice(1)*1)||10) ;
Game.hand.push(card);
return JSON.stringify(Game, null, "\t");
},//end draw()
deck: suites.map(function(a,b){
return "AA23456789XJQK".split("").join(" "+a).slice(1);
}).join(" ").trim().split(" ")
.filter(Boolean)
.map(function shuffle(a,b,c){if(!b){shuffle.r=c.slice();}return shuffle.r.splice(Math.random()*(c.length-b),1)[0];})
}
</textarea>
</label>

<label class='box'><b class='title'></b>
<textarea class="textbox" rows="35" name="OUT" id="OUT" tabindex="1" cols="80" onchange="IN.title=IN.value.length+' Bytes.';return true; " ></textarea>
</label>

<br />

<script type="text/late" id="late">

// the button code:

if(!window.Game){eval(IN.value);window.Game=Game;}
Game.draw();

</script>
<script>
//just for demo, ignore this code....

(function(){
var elmNames=["IN","OUT"];
window.elms=elmNames.map(el).map(function(a,b){return window[elmNames[b]]=a; });
}());

function showTab(tabId){
elms.map(function hide(a){ a.style.display="none"; });
el(tabId).style.display='block';
}


window.main=function ol() {
var resp=eval(el("late").textContent);
if(resp.split){ OUT.value=resp;}else{ OUT.value=JSON.stringify(resp, null, "\t"); }
};

</script>
</body>
</html>

pdiddles03
10-02-2012, 07:14 PM
Thanks for the reply.

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.

Old Pedant
10-03-2012, 12:33 AM
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?

pdiddles03
10-03-2012, 06:11 PM
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.

Old Pedant
10-03-2012, 09:19 PM
This line
start.setAttribute('onclick', 'gamestart()');
should be
start.setAttribute('onclick', gamestart);

or could even be simpler:
start.onclick = gamestart;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum