锅打灰太狼







* {padding: 0;margin: 0;}
#outer {background: url(img/game_bg.jpg);width: 320px;height: 480px;position: relative;margin: 0 auto;}
#scoring {position: absolute;top: 13px;left: 65px; font-weight: bold;font-size: 20px; color: white; }
#countDown {position: absolute; background: url(img/progress.png) no-repeat; width: 180px; height: 16px; left: 63px; top: 66px;}
#countDown img {position: absolute; }
#menu { position: absolute; width: 320px; text-align: center; top: 220px; left: 0;}
#start { line-height: 50px; font-size: 30px;font-weight: bold;color: green;text-decoration: none; text-shadow: 0 0 5px red;display: block;}





0




        </div>

        <div id="menu">
            <a href="javascript:void(0)" id="start">开始</a>
        </div>
    </div>

    <script type="text/javascript">
        //随机函数(坑、狼的种类)
        function rand(min, max) {
            return parseInt(Math.random() * (max - min + 1) + min);
        }
        //分数
        var scoring = document.getElementById('scoring');
        //倒计时
        var countDown = document.getElementById('countDown');
        //狼窝
        var wolfs = document.getElementById('wolfs');
        var menu = document.getElementById('menu');
        var start = document.getElementById('start');
        var arrPos = [{l: "98px",t: "115px"}, 
                    {l: "17px",t: "160px"}, 
                    {l: "15px",t: "220px"}, 
                    {l: "30px",t: "293px"},
                    {l: "122px",t: "273px"},
                    {l: "207px",t: "295px"},
                    {l: "200px",t: "211px"}, 
                    {l: "187px",t: "141px"}, 
                    {l: "100px",t: "185px"}];
        //计分
        function scoringFn(obj){
            var scoringNum = parseInt(scoring.innerHTML);
            if (obj.type == "h") {
                scoring.innerHTML = scoringNum + 10;
            } else{
                scoring.innerHTML = scoringNum - 10;
            }
        }
        //倒计时
        var countDownTimer = null;
        var countDownWidth = countDown.offsetWidth;
        var countDownBol = false;
        countDownTimer = setInterval(function(){
            if (countDownBol) {
                countDownWidth--;
                if (countDownWidth<=0) {
                    clearInterval(createWolfsTimer);
                    clearInterval(countDownTimer);
                    var score = scoring.innerHTML;
                    alert("您的分数为"+score);
                    window.location.reload();
                }
                countDown.style.width = countDownWidth+"px";
            }
        },150);
        var createWolfsTimer = null;
        start.onclick = function(){
            menu.style.display = "none";
            countDownBol = true;
            createWolfsTimer = setInterval(function(){
                //创建狼��
                var wolf = new Image();
                //��的类型
                wolf.type = rand(0,100)>80 ? "x" : "h";
                wolf.index = 0;
                wolf.src = "img/"+wolf.type+wolf.index+".png";
                //找坑
                //找到狼窝里的所有img标签
                var childs = wolfs.children;
                //下面的两个东西是循环内使用的
                var bol = true;
                var r = 0;  //装我们找到的没有狼的坐标
                while (bol){
                    r = rand(0,arrPos.length-1);
                    for (var i=0;i<childs.length;i++) {
                        if (childs[i].offsetLeft == parseInt(arrPos[r].l)) {
                            break;
                        }
                    }
                    if (i == childs.length) {
                        bol = false;
                    }
                }
                //交出循环后的坐标
                wolf.style.position = "absolute";
                wolf.style.left = arrPos[r].l;
                wolf.style.top = arrPos[r].t;
                wolfs.appendChild(wolf);
                //狼向上的动画
                wolf.timer = setInterval(function(){
                    wolf.index++;
                    if (wolf.index > 4) {
                        clearInterval(wolf.timer);
                        wolf.downfn();
                    }
                    wolf.src = "img/"+wolf.type+wolf.index+".png";
                },150);
                //狼向下
                wolf.downfn = function(){
                    wolf.downTimer = setInterval(function(){
                        wolf.index--;
                        if (wolf.index <= 0) {
                            clearInterval(wolf.downTimer);
                            //让狼滚
                            wolfs.removeChild(wolf);
                        }
                        wolf.src = "img/"+wolf.type+wolf.index+".png";
                    },150);
                }
                wolf.wolfClick = true;
                wolf.onclick = function(){
                    if (wolf.wolfClick == false) {
                        return;
                    }
                    wolf.wolfClick = false;
                    scoringFn(wolf);
                    wolf.index = 5;
                    //干掉两个出浪的动画
                    clearInterval(wolf.timer);
                    clearInterval(wolf.downTimer);
                    wolf.clickTimer = setInterval(function(){
                        wolf.index++;
                        wolf.src = "img/"+wolf.type+wolf.index+".png";
                        if(wolf.index>=9){
                            clearInterval(wolf.clickTimer);
                            wolfs.removeChild(wolf);
                        }
                    },150);
                }

            },800);
        }
    </script>
</body>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值