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. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 抽奖&游戏

jquery点击福袋金币蹦出散落抽奖动画特效

jquery点击福袋金币蹦出散落抽奖动画特效
  抽奖&游戏
 91353  0

jquery设置数字范围随机取号抽奖代码

可设置两个数字:最小值和最大值,点击开始滚动数字!暂停就随机抽取数字。
  抽奖&游戏
 5875  0

javascript创建的在线翻卡牌游戏源码

这是一款翻牌小游戏代码,有16张问号卡牌中,需要鼠标点击翻出两张卡牌都有相同的图案,但每张卡牌都是随机放置的,找卡牌没有时间限制。
  抽奖&游戏
 71076  0

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

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

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

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