javascript小游戏

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js游戏</title>
<script type="text/javascript">
 var x=10;
 //x=parseInt(Math.random()*(1000-1))+1;
  for(var i=0;i<10;i++){
  var num=prompt("请输入你猜测的数字","");
  if (num!=null && num!="")
    {
  if(num==x){
   switch(i){
    case 0:
     alert('真神啦,猜对了!');
     i=10;
     break;
    case 1:
     alert('厉害,对啦!');
     i=10;
     break;
    case 2:
     alert('真棒,对啦!');
     i=10;
     break;
    case 3:
     alert('好好,对啦!');
     i=10;
     break;
    case 4:
     alert('不容易,对啦!');
     i=10;
     break;
    case 5:
     alert('将就,对啦!');
     i=10;
     break;
    case 6:
     alert('有点慢,对啦!');
     i=10;
     break;
    case 7:
     alert('下次快点,对啦!');
     i=10;
     break;
    case 8:
     alert('赶上啦,对啦!');
     i=10;
     break;
    case 9:
     alert('最后机会,对啦!');
     i=10;
     break;
   }
  }
  if(i==9){
   alert('笨蛋,10次都猜不对!');
  }
  if(num>x){
   document.write("您已经猜了" + eval(i+1) + "次," + num +"," + "大了!<br>");
  }
  if(num<x){
   document.write("您已经猜了" + eval(i+1) + "次," + num +"," + "小了!<br>");
  }
    }else{
  alert('不能为空'); 
 }
  }
</script>
</head>

<body>
<div id="div1"></div>
</body>
</html>
lenovo 21:09:50
  <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>图片浮动</title>
</head>

<body>
<DIV id=img1 style="Z-INDEX: 100; LEFT: 2px; WIDTH: 59px; POSITION: absolute; TOP: 43px; HEIGHT: 61px;
 visibility: visible;"><table width="10" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="18" align="center"><a href="#" onClick="javascript:document.getElementByIdx('img1').style.visibility='hidden';"></a></td>
  </tr>
  <tr>
    <td><img src="123.jpg" width="111" height="127"></td>
  </tr>
</table>
</DIV>
<SCRIPT>
 var xPos = 300;
var yPos = 200;
var step = 1;
var delay = 30;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
img1.style.top = yPos;
function changePos()
{
 width = document.body.clientWidth;
 height = document.body.clientHeight;
 Hoffset = img1.offsetHeight;
 Woffset = img1.offsetWidth;
 img1.style.left = xPos + document.body.scrollLeft;
 img1.style.top = yPos + document.body.scrollTop;
 if (yon)
  {yPos = yPos + step;}
 else
  {yPos = yPos - step;}
 if (yPos < 0)
  {yon = 1;yPos = 0;}
 if (yPos >= (height - Hoffset))
  {yon = 0;yPos = (height - Hoffset);}
 if (xon)
  {xPos = xPos + step;}
 else
  {xPos = xPos - step;}
 if (xPos < 0)
  {xon = 1;xPos = 0;}
 if (xPos >= (width - Woffset))
  {xon = 0;xPos = (width - Woffset);   }
 }
 
 function start()
  {
   img1.visibility = "visible";
  interval = setInterval('changePos()', delay);
 }
 function pause_resume()
 {
  if(pause)
  {
   clearInterval(interval);
   pause = false;}
  else
  {
   interval = setInterval('changePos()',delay);
   pause = true;
   }
  }
 start();
 </SCRIPT>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值