杏阳 发表于 2012-8-6 18:45:12

javascript小游戏21点(借鉴)

<html>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<head>
<title>21点游戏</title>
<style type="text/css">
<!--
body {font-family: "宋体"; font-size: 9pt; margin-top: 0px; margin-left: 4px; margin-right: 0px}
A { COLOR: black; FONT-SIZE: 13px; FONT-WEIGHT: 400; TEXT-DECORATION: none }
A:hover { COLOR: red; FONT-SIZE: 13px; FONT-WEIGHT: 400; TEXT-DECORATION: underline }
a:active   { font: 9pt "宋体"; cursor: hand; color: #FF0033 }
--></style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#fef4d9">
<br>
<center><font color=red face="隶书" size=6>21点游戏</font></center>
<br>
<center>
<table border=5 bordercolor=blue borderlight=green>
<tr><td align=center><font size=5 color=red face="Arial, Helvetica, sans-serif"><strong>下面框中为脚本显示区</strong></font></td></tr>
<tr><td align=center height=80 width=400>
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from non-JavaScript browsers
function random(maxValue)
{
   day = new Date();
   hour = day.getHours();
   min = day.getMinutes();
   sec = day.getSeconds();
   return (((hour + 1) * (min + 1) * sec) % maxValue) + 1;
}
function pickSuit()
{
   suit = random(4);
   if(suit == 1)
      return "Spades";
   if(suit == 2)
   return "Clubs";
   if(suit == 3)
      return "Diamonds";
   return "Hearts";
}
function cardName(card)
{
   if(card == 1)
      return "Ace";
   if(card == 11)
      return "Jack";
   if(card == 12)
      return "Queen";
   if(card == 13)
      return "King";
   return "" + card;
}
function cardValue(card)
{
   if(card == 1)
      return 11;
   if(card > 10)
      return 10;
   return card;
}
function PickACard(strWho)
{
   card = random(13);
   suit = pickSuit();
   //alert(strWho + " picked the " + cardName(card) + " of " + suit);
   return cardValue(card);
}
function NewHand(form)
{
   form.dealer.value = 0;
   form.you.value = 0;
   form.dealer.value = eval(form.dealer.value) + PickACard("Dealer");
   form.you.value = eval(form.you.value) + PickACard("You");
}
function Dealer(form)
{
   while(form.dealer.value < 17)
   {
      form.dealer.value = eval(form.dealer.value) + PickACard("Dealer");
   }
}
function User(form)
{
   form.you.value = eval(form.you.value) + PickACard("You");
   if(form.you.value > 21)
   {
      alert("不好意思,你爆了!");
   }
}
function LookAtHands(form)
{
   if(form.dealer.value > 21)
   {
      alert("庄家爆了,你赢!");
   }
   else   if(form.you.value > form.dealer.value)
   {
      alert("你赢了!");
   }
   else
   if(form.dealer.value == form.you.value)
   {
      alert("Push!");
   }
   else
   {
      alert("庄家赢了!");
   }
}
//-->
</SCRIPT>
<FORM>
<TABLE BORDER=3>
<TR>
<TD>庄家有</TD>
<TD><INPUT TYPE=TEXT NAME=dealer>点</TD>
</TR>
<TR> <TD>你有</TD>
<TD><INPUT TYPE=TEXT NAME=you>点</TD>
</TR>
</TABLE>
<INPUT TYPE=BUTTON VALUE="再要一张" onClick=User(this.form)>
<INPUT TYPE=BUTTON VALUE="亮牌">
<INPUT TYPE=BUTTON VALUE="重新发牌" onClick=NewHand(this.form)>
</td></tr></table></center>
</body>
</html>




小游戏.html
http://kuai.xunlei.com/d/OISSCYMVVBFL

nkc3g4 发表于 2012-8-6 21:44:33

不错{:soso__2090105551747574536_3:}
页: [1]
查看完整版本: javascript小游戏21点(借鉴)