Stap 6: Blackjack.
[code]
< html >
< head >
< SCRIPT LANGUAGE = "JavaScript" >
<!--oorspronkelijke: Mike McGrath (mike_mcgrath-->
<!--Web Site: http://home.clara.net/mikem-->
<!--beginnen
var gameOver; var cardCount;
functie Shuffle(max) {}
var num=Math.random () * max;
keren Math.round (num) + 1;
}
functie getSuit() {}
Pak = Shuffle(4);
if(SUIT == 1) return "Schoppen";
if(SUIT == 2) return "Clubs";
if(SUIT == 3) return "Diamonds";
anders terug "Hart";
}
functie cardName(card) {}
if(Card == 1) return "Ace";
if(Card == 11) return "Jack";
if(Card == 12) return "Queen";
if(Card == 13) return "King";
terug "" + kaart;
}
functie cardValue(card,strWho) {}
if(Card == 1) {}
Als (strWho == "You" & & document.display.you.value > 10) {}
document.display.say2.Value=document.display.say2.value+ "Low"; terug 1;}
anders terug 11; }
Als (kaart > 10) terugkeer 10;
retourneren van de kaart;
}
functie PickACard(strWho) {}
kaart = Shuffle(12);
Pak = getSuit();
Als (strWho == "You")
document.display.say2.Value=(cardName(Card) + "" + pak);
anders
document.display.say1.Value=(cardName(Card) + "" + pak);
Return cardValue(card,strWho);
}
functie NewHand(form) {}
Als (gameOver! = 0)
{form.say1.value= ("Hand in het spel!"); form.say2.value=(""); terugkeer;}
anders
{form.dealer.value = 0; form.you.value = 0; cardCount = 0;
Form.dealer.Value = eval(form.dealer.value) + PickACard("Dealer");
Form.You.Value = eval(form.you.value) + PickACard("You");
gameOver = -1; cardCount += 1;}
}
functie Dealer(form) {}
Als (gameOver == 0)
{form.say1.value= ("de kaarten Deal!"); form.say2.value=(""); terugkeer;}
anders
if(Form.You.value<10)
{form.say1.value= ("niet minder dan tien!"); form.say2.value= ("Take een Hit!"); terugkeer;}
anders
Als (cardCount < 2)
{form.say1.value= ("Minimum 2 kaarten!"); form.say2.value= ("Hit opnieuw!"); terugkeer;}
anders
terwijl (form.dealer.value < 17)
{form.dealer.value = eval(form.dealer.value) + PickACard("Dealer");}
}
functie User(form) {}
Als (gameOver == 0)
{form.say1.value= ("de kaarten Deal!"); form.say2.value=(""); terugkeer;}
anders
{cardCount += 1; form.say1.value= ("You Get...");
Form.You.Value = eval(form.you.value) + PickACard("You");}
if(Form.You.Value > 21)
{form.say1.value= ("You Busted!");
gameOver = 0; Form.numgames.Value=eval (form.numgames.value) -1;}
}
functie LookAtHands(form) {}
Als (gameOver == 0 || form.you.value < 10 || cardCount < 2) {terugkeer;}
anders
if(Form.dealer.Value > 21)
{form.say1.value= ("huis bustes!"); form.say2.value= ("You Win! $$$$$$");
gameOver = 0; Form.numgames.Value=eval (form.numgames.value) + 1;}
anders
if(Form.You.Value > Form.dealer.Value)
{form.say1.value= ("You Win!"); form.say2.value=("$$$");
gameOver = 0; Form.numgames.Value=eval (form.numgames.value) + 1;}
anders
if(Form.dealer.Value == form.You.Value)
{form.say1.value= ("Game Tied!"); form.say2.value= ("Try Again!");
gameOver = 0; Form.numgames.Value=eval (form.numgames.value) -1;}
anders
{form.say1.value= ("huis wint!"); form.say2.value= ("Tough Luck!");
gameOver = 0; Form.numgames.Value=eval (form.numgames.value) -1;}
}
functie setBj() {}
gameOver = 0; cardCount = 0;
document.display.dealer.value= "";
document.display.You.value= "";
document.display.numgames.value="0";
document.display.say1.value= "Hit 'Deal'";
document.display.say2.value= 'Kunt starten!';
}
--> Einde
< / script >
< / head >
< BODY OnLoad="setBj()" >
< center >
< formuliernaam = "Toon" >
< tabel bgcolor = "#c0c0c0" border = "1" cellspacing = "0" cellpadding = "3" >
< tr >
< td >< center > Score: < / center >< /td >
< td >< center > Dealer < / center >< /td >
< td >< center >< input type = tekstnaam = "dealer" size = "2" >< / center >< /td >
< td >< center > kaart(en): < input type = tekstnaam = grootte van de "say1" = "18" value = "" >< / center >< /td >
< /tr >
< tr >
< td >< center >< input type = tekstnaam = grootte van de "numgames" = "3" value = "0" >< / center >< /td >
< td >< center > speler < / center >< /td >
< td >< center >< input type = tekstnaam = "u" size = "2" >< / center >< /td >
< td >< center > kaart(en): < input type = tekstnaam = grootte van de "say2" = "18" value = "" >< / center >< /td >
< /tr >
< tr >
< td >< center >< input type = button value = "Deal" onClick="NewHand(this.form)" >< / center >< /td >
< td colspan = 3 >< center >
< input type = button value = "Stand" onClick="Dealer(this.form); LookAtHands(this.form);" >
< input type = button value = "Hit"onClick="User(this.form)" >< / center >< /td >< /tr >
< / table >
< / form >
< / center >
< / body >
< / html >
[/ code]