1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| $(function () { $(".rules").click(function () { $(".rule").stop().fadeIn(100);
clearInterval(wolfTimer); stopWolfAnimation();
});
$(".close").click(function () { $(".rule").stop().fadeOut(100); startWolfAnimation(); });
$(".start").click(function () { $(this).stop().fadeOut(100); progressHandler(); startWolfAnimation(); });
$(".reStart").click(function () { $(".mask").stop().fadeOut(100); progressHandler(); $(".score").text(0); startWolfAnimation(); });
function progressHandler() { $(".progress").css({ width: 180 }); var timer = setInterval(function () { var progressWidth = $(".progress").width(); progressWidth -= 1; $(".progress").css({ width: progressWidth }); if(progressWidth <= 0){ clearInterval(timer); $(".mask").stop().fadeIn(100); stopWolfAnimation(); } }, 100); }
var wolfTimer; function startWolfAnimation() { var wolf_1=['./images/h0.png','./images/h1.png','./images/h2.png','./images/h3.png','./images/h4.png','./images/h5.png','./images/h6.png','./images/h7.png','./images/h8.png','./images/h9.png']; var wolf_2=['./images/x0.png','./images/x1.png','./images/x2.png','./images/x3.png','./images/x4.png','./images/x5.png','./images/x6.png','./images/x7.png','./images/x8.png','./images/x9.png']; var arrPos = [ {left:"100px",top:"115px"}, {left:"20px",top:"160px"}, {left:"190px",top:"142px"}, {left:"105px",top:"193px"}, {left:"19px",top:"221px"}, {left:"202px",top:"212px"}, {left:"120px",top:"275px"}, {left:"30px",top:"295px"}, {left:"209px",top:"297px"} ];
var $wolfImage = $("<img src='' class='wolfImage'>"); var posIndex = Math.round(Math.random() * 8); $wolfImage.css({ position: "absolute", left:arrPos[posIndex].left, top:arrPos[posIndex].top }); var wolfType = Math.round(Math.random()) == 0 ? wolf_1 : wolf_2; window.wolfIndex = 0; window.wolfIndexEnd = 5; wolfTimer = setInterval(function () { if(wolfIndex > wolfIndexEnd){ $wolfImage.remove(); clearInterval(wolfTimer); startWolfAnimation(); } $wolfImage.attr("src", wolfType[wolfIndex]); wolfIndex++; }, 300);
$(".container").append($wolfImage);
gameRules($wolfImage); }
function gameRules($wolfImage) { $wolfImage.one("click",function () { window.wolfIndex = 5; window.wolfIndexEnd = 9;
var $src = $(this).attr("src"); var flag = $src.indexOf("h") >= 0; if(flag){ $(".score").text(parseInt($(".score").text()) + 10); }else{ $(".score").text(parseInt($(".score").text()) - 10); } }); } function stopWolfAnimation() { $(".wolfImage").remove(); clearInterval(wolfTimer); } });
|