jquery移动端打地鼠类小游戏源码

所属分类: 网页特效-抽奖&游戏    2024-11-05 08:59:19

jquery移动端打地鼠类小游戏源码 ie兼容10
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery移动端打地鼠类小游戏源码(共30个文件)

    • index.html

使用方法

    $(document).ready(function () {
        var height = $(window).height();
        var textScore = $("#textScore");
        var ulList = $(".theMouseDiv");
        $(".gameIndex").css("height", height + 'px');
        $(".gamePlay").css("height", height + 'px');
        $(".ruleBtn").click(function () {
            $(".gameHideBg,.gameRule").show();
        });
        //关闭规则
        $("#closeRule").click(function () {
            $(".gameHideBg,.gameRule").hide();
        });
        //开始游戏
        $(".startBtn").click(function () {
            $(".gameIndex").hide();;
            $(".gamePlay").show();
            init();
            payGame();
        });
        //再来一次
        $(".againBtn").click(function () {
            $(".overShow").hide();
            init();
            payGame();
        });
        //游戏失败再来一次
        $(".failBtn").click(function () {
            $(".gameHideBg,.gameResult,.overShow,.failBtn").hide();
            init();
            payGame();
        });
        //关闭游戏结果
        $("#closeResult").click(function () {
            $(".gameHideBg,.gameResult,.successBtn,.failBtn").hide();
        });
        //点击查看奖品
        $(".successBtn").click(function () {
            $(".gameResult,.successBtn").hide();
            $(".prizeResult").show();
        });
        //关闭奖品页
        $("#closePrize").click(function () {
            $(".gameHideBg,.prizeResult,.gameHideBg").hide();
        });

        //打击病毒
        var _that = 0;
        ulList.click(function () {
            //判断是否有病毒
            if (this.children.length != 0 && _that != this) {
                $("#fight").remove();
                $("#musicDiv").append(
                    '');
                var who = $(this.children[0]).attr("src");
                who = who.substr(who.length - 6, 1);
                var that = this;
                switch (who) {
                    case 'a':
                        that.children[0].src = 'Img/a2.png';
                        break;
                    case 'b':
                        that.children[0].src = 'Img/b2.png';
                        score += 8;
                        $(that).next().next().text('+8');
                        $(that).next().next().show();
                        break;
                    case 'c':
                        that.children[0].src = 'Img/c2.png';
                        score += 10;
                        $(that).next().next().text('+10');
                        $(that).next().next().show();
                        break;
                    case 'd':
                        that.children[0].src = 'Img/d2.png';
                        score += 5;
                        $(that).next().next().text('+5');
                        $(that).next().next().show();
                        break;
                }
                $(this).next().show();
                setTimeout(function () {
                    $(that).next().hide();
                    $(that).next().next().hide();
                }, 200)
                textScore.text(score);
            }
            _that = this;
        });
        //初始化
        function init() {
            score = 0;
            time = 30;
            $("#textScore").text('0')
        }
        //开启游戏
        function payGame() {
            document.getElementById("gameMusic").play();
            var timeRun = $(".timeRun");
            var ulList = $(".theMouseDiv");
            var index = 0;
            var mouseTimer = setInterval(function () {
                var idx = parseInt(Math.random() * ulList.length);
                if (idx === index) {
                    if (idx < 8) idx++; else idx--; } var select = randomNum(1, 4); var code = +new Date(); switch (select) { case 1: if (ulList[idx].children.length == 0) ulList[idx].innerHTML = '';
                        break;
                    case 2:
                        if (ulList[idx].children.length == 0)
                            ulList[idx].innerHTML = '';
                        break;
                    case 3:
                        if (ulList[idx].children.length == 0)
                            ulList[idx].innerHTML = '';
                        break;
                    case 4:
                        if (ulList[idx].children.length == 0)
                            ulList[idx].innerHTML = '';
                        break;
                }
                $(".theMouse").animate({
                    top: '0px'
                }, 1000).animate({
                    top: '60px'
                }, 1000);
                index = idx;
                setTimeout(function () {
                    $('.theMouse[data-id="' + code + '"]').remove();
                }, 1700);
            }, 500);
            var runTimer = setInterval(function () {
                time--;
                timeRun.text(time);
                if (time === 0) {
                    clearInterval(runTimer);
                    clearInterval(mouseTimer);
                    $('.theMouse').remove();
                    $(".gameHideBg,.overShow").show();
                    document.getElementById("gameMusic").pause();
                    setTimeout(function () {
                        $(".gameResult").show();
                        $(".reslutScore").text(score);
                        if (score < 85) { document.getElementById("gameOver").play(); $(".resultTitle").text("挑战失败"); $(".reslutText,.failBtn").show(); } else { document.getElementById("gameSuccess").play(); $(".resultTitle").text("挑战成功"); $(".reslutText").hide(); $(".successBtn").show(); } }, 500); } }, 1000); } //随机生成指定范围数字 function randomNum(minNum, maxNum) { switch (arguments.length) { case 1: return parseInt(Math.random() * minNum + 1, 10); break; case 2: return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10); break; default: return 0; break; } } });

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 抽奖&游戏

javascript谷歌chrome浏览器自带的小恐龙游戏代码

一款谷歌浏览器恐龙跳跳小游戏源码,这是谷歌浏览器内置的离线恐龙小游戏,按键盘中的空格键可开始、跳跃。
  抽奖&游戏
 31737  0

jquery随机格子抽奖特效代码

通过鼠标点击抽奖按钮多个奖品格子依次随机闪烁摇奖过程,最终抽奖结束奖品格子闪烁摇奖停止。
  抽奖&游戏
 41034  0

CSS3剪辑路径猜猜我是谁特效代码

一款猜猜我是谁游戏特效,通过css剪辑一张图片当中人物眼部位置图片,鼠标悬停会更改剪辑路径,显示人物完整图像。
  抽奖&游戏
 5713  0

原生js圣诞老人过悬崖游戏源码

一款html5响应式圣诞老人过悬崖的游戏代码,任何地方按住不懂显示柱子,放手后可架桥。
  抽奖&游戏
 7883  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论