当前位置: 代码迷 >> Java相关 >> 21点小游戏代码求注释
  详细解决方案

21点小游戏代码求注释

热度:322   发布时间:2012-06-29 19:09:04.0
21点小游戏代码求注释
<html>
<head>
<title>Js版21点游戏</title>
</head>
<body>
<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();
   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("YOU WIN!你赢了!");

   }

   else
   if(form.dealer.value == form.you.value)

   {

      alert("Push!");

   }

   else

   {
      alert("庄家赢了!");

   }
}
//-->
</SCRIPT>

<CENTER><H2>21点</H2></CENTER>
<CENTER>开始游戏请点击“洗牌”</CENTER>
<HR>
<CENTER>
<FORM>
<TABLE BORDER=3>
<TR>
  <TD>庄家:</TD>
  <TD><INPUT TYPE=TEXT NAME=dealer size="20">点</TD>
</TR>
<TR>
  <TD>你:</TD>
  <TD><INPUT TYPE=TEXT NAME=you size="20">点</TD>
</TR>
</TABLE>
<P>
<CENTER>
<INPUT TYPE=BUTTON VALUE="再来一张" onClick=User(this.form)>
<INPUT TYPE=BUTTON VALUE="亮牌" onClick="Dealer(this.form);LookAtHands(this.form);">
<INPUT TYPE=BUTTON VALUE="洗牌" onClick=NewHand(this.form)>
</CENTER>
</body>
</html>
搜索更多相关的解决方案: head  小游戏  function  return  title  

----------------解决方案--------------------------------------------------------
  相关解决方案