| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1163 人关注过本帖
标题:21点小游戏代码求注释
只看楼主 加入收藏
wl182800541
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-6-29
收藏
 问题点数:0 回复次数: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 
2012-06-29 19:09
快速回复:21点小游戏代码求注释
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019534 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved