资源描述:一款手机移动端在线打地鼠益智类小游戏,css采用rem单位,自适应各种手机端屏幕,设置了游戏背景、打击效果、游戏通过、游戏失败多种背景乐和音效增加趣味性!
使用方法
$(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. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服