js.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. // JavaScript Document
  2. var isover=false;
  3. $(function (){
  4. var starx;
  5. var stary;
  6. var rw=document.getElementById("rw");
  7. var movex;
  8. var movey;
  9. var time=1540;//计时器重置
  10. var times=1600;
  11. var time1;
  12. var time2;
  13. var width=$(document).width();
  14. var height=$(document).height();
  15. var wheight=$(window).height();//获取浏览器高度
  16. var iheight=$("#img p img").height();//获取图片高度
  17. var top=$("#img p").css("top");//p的top值
  18. var rheight=$("#gamesstart .rw").height();//获取人物高度
  19. var rwidth=$("#gamesstart .rw").width()/2;///获取人物宽度的一半
  20. var fenshu=0;
  21. var shijian=90;
  22. var topyy=wheight-rheight-20;//人物跳跃
  23. var texta=[
  24. '您被<span class="red">90%</span>的挑战者击败,亲,您动了吗,您真的动了吗!',
  25. '您击败了<span class="red">40%</span>的挑战者,差一点就杯具了!',
  26. '您击败了<span class="red">60%</span>的挑战者,再不努力您就要老了!',
  27. '您击败了<span class="red">80%</span>的挑战者,无影手已经到了炉火纯青的境界',
  28. '您击败了<span class="red">99%</span>的挑战者,如此深厚的功力看起来萌萌哒!',
  29. ];
  30. var textb=[
  31. '懒人<br>症患者',
  32. '危险人物',
  33. '淡定君',
  34. '梅超风<br>接班人',
  35. '超级无敌<br>无影手',
  36. ];
  37. $(".jiafen").css("top",wheight-80);//设置加分top属性
  38. //$(".jiafen").animate({top:wheight-160,opacity:0},500)
  39. //游戏核心,游戏开始
  40. function start(){
  41. $("#rw").css("display","block");
  42. function run(){
  43. var panduan=false;
  44. var image=Math.floor(Math.random() * 7);//图片随机数
  45. var left=Math.floor(Math.random()*(width-30));//随机left
  46. var i=Math.floor(Math.random()*5);//标签的随机数
  47. var imgw=$("#img p").eq(i).children("img").width()/2; ///获取当前动画图片的宽度的一半
  48. var imgl=parseInt($("#img p").eq(i).css("left"));
  49. $("#img p").eq(i).children("img").attr("src","img/"+image+".png");
  50. var topy;
  51. if(topy==wheight-rheight-20){}
  52. $("#img p").eq(i).animate({top:wheight},time,function(){
  53. if(movex-rwidth>imgl-rwidth&&movex-rwidth<imgl+imgw*2)
  54. {
  55. //分数判断
  56. if(image==6)
  57. {
  58. $("#img p").eq(i).children("img").attr("src","img/baozha.png");
  59. $("#img p").eq(i).css("top",wheight-rheight-80);
  60. $("#img p").eq(i).children("img").css({"width":"80px","height":"auto"});
  61. setTimeout(function(){$("#img p").eq(i).children("img").attr("src","img/"+image+".png").css({"width":"36px","height":"auto"});//此处更改了图片的属性
  62. $("#img p").eq(i).css({top:top,left:-120});$("#img p").eq(i).animate({left:left},100);},100)
  63. $("#fenshu").text(fenshu-=30);
  64. if(fenshu<0){$("#fenshu").text("0");};
  65. $(".jiafen").css({"display":"block"});
  66. $(".jiafen img").attr("src","img/kl.png");
  67. $(".jiafen span").text("-30");
  68. $(".jiafen").animate({top:wheight-160,opacity:0},500,function(){
  69. $(".jiafen").css({"top":wheight-80,"display":"none","opacity":1});
  70. })
  71. }
  72. else if(image==4)
  73. {
  74. $("#fenshu").text(fenshu+=40);
  75. $(".jiafen img").attr("src","img/xl.png");
  76. $(".jiafen").css({"display":"block"});
  77. $(".jiafen span").text("+40");
  78. $(".jiafen").animate({top:wheight-160,opacity:0},500,function(){
  79. $(".jiafen").css({"top":wheight-80,"display":"none","opacity":1});
  80. });
  81. $("#img p").eq(i).css({top:top,left:-120});$("#img p").eq(i).animate({left:left},100);
  82. }
  83. else
  84. {
  85. $("#fenshu").text(fenshu+=20);
  86. $(".jiafen").css({"display":"block"});
  87. $(".jiafen img").attr("src","img/xl.png");
  88. $(".jiafen span").text("+20");
  89. $(".jiafen").animate({top:wheight-160,opacity:0},500,function(){
  90. $(".jiafen").css({"top":wheight-80,"display":"none","opacity":1});
  91. })
  92. $("#img p").eq(i).css({top:top,left:-120});$("#img p").eq(i).animate({left:left},100);
  93. }
  94. }
  95. else
  96. {
  97. $("#img p").eq(i).animate({top:wheight},100,function(){
  98. $("#img p").eq(i).css({top:top,left:"-100%"});
  99. $("#img p").eq(i).animate({left:left},100);
  100. });
  101. }
  102. if(shijian<10&&shijian>0)
  103. {
  104. $("#img p").eq(i).css({top:top,left:"-100%"});
  105. $("#img p").eq(i).animate({left:left},100);
  106. topyy=wheight-rheight/2;
  107. }
  108. });
  109. }
  110. time1=setInterval(run,times);
  111. //倒计时
  112. function djs(){
  113. $("#shijian").text(shijian-=1);
  114. /*setTimeout(run,times+300);
  115. if(shijian<10&&shijian>0)
  116. {time=450;times=700;setTimeout(run,times-100);}
  117. else if(shijian%6==0)
  118. {time-=90;times-=100;}
  119. */
  120. if(shijian<=0)
  121. { if(isover){
  122. return;
  123. }
  124. isover=true;
  125. clearInterval(time1);
  126. clearInterval(time2);
  127. //判断分数
  128. setTimeout(function(){
  129. window.score=$("#fenshu").text();
  130. if(window.score<400)
  131. {
  132. $("#erwema").attr("src","img/canyujiang.png");
  133. //$("#yhimg img").attr("src","img/yyhj10.png");
  134. $("#textb").html(texta[0]);
  135. $("#texta").html(textb[0]);
  136. }
  137. else if(window.score>=400&&window.score<600)
  138. {
  139. $("#erwema").attr("src","img/sandengjiang.png");
  140. //$("#yhimg img").attr("src","img/yyhj20.png");
  141. $("#textb").html(texta[1]);
  142. $("#texta").html(textb[1]);
  143. }
  144. else if(window.score>=600&&window.score<800)
  145. {
  146. $("#erwema").attr("src","img/sidengjiang.png");
  147. //$("#yhimg img").attr("src","img/yhj10.png");
  148. $("#textb").html(texta[2]);
  149. $("#texta").html(textb[2]);
  150. }
  151. else if(window.score>=800&&window.score<900)
  152. {
  153. $("#erwema").attr("src","img/erdengjiang.png");
  154. // $("#yhimg img").attr("src","img/yhj30.png");
  155. $("#textb").html(texta[3]);
  156. $("#texta").html(textb[3]);
  157. }
  158. else
  159. {
  160. $("#erwema").attr("src","img/yidengjiang.png");
  161. //$("#yhimg img").attr("src","img/yhj50.png");
  162. $("#textb").html(texta[4]);
  163. $("#texta").html(textb[4]);
  164. };
  165. $(".gamesjs").css("display","block");
  166. $("#rw").css("display","none");
  167. //提交分数z
  168. var uid=parseInt($("#uid").val());
  169. //分享开始
  170. allscore=fenshu;
  171. if(allscore<400)
  172. {
  173. title='挑战无影手,快来试试身手吧。';
  174. msg='我在挑战无影90%的被挑战者击败,小伙伴们,快来帮帮我吧。';
  175. }
  176. if(allscore>=400&&allscore<600){
  177. title='挑战无影手,快来试试身手吧。';
  178. msg='我在挑战无影手中击败了40%的挑战者,差一点就杯具了!';
  179. }
  180. if(allscore>=600&&allscore<800){
  181. title='挑战无影手,快来试试身手吧。';
  182. msg='我在挑战无影手中击败了60%的挑战者,再不努力您就要老了!';
  183. }
  184. if(allscore>=800&&allscore<900){
  185. title='挑战无影手,快来试试身手吧。';
  186. msg='我在挑战无影手中击败了80%的挑战者,无影手已经到了炉火纯青的境界!';
  187. }
  188. if(allscore>900){
  189. title='挑战无影手,快来试试身手吧。';
  190. msg='我在挑战无影手中击败了90%的挑战者,如此深厚的功力看起来萌萌哒!';
  191. }
  192. $("#title").val(title);
  193. $("#msg").val(msg);
  194. console.log(window.score);
  195. //updateShare(window.score);
  196. //Play68.setRankingScoreDesc(window.score);
  197. },2000);
  198. }
  199. }
  200. time2=setInterval(djs,1000);
  201. //触摸开始
  202. rw.addEventListener("touchstart",function(e){
  203. if($(".index").css("display")=="none"){
  204. e.preventDefault();//禁止滚屏;
  205. };
  206. var touch=e.touches[0];
  207. var x=touch.pageX;
  208. var y=touch.pageY;
  209. starx=x;
  210. stary=y;
  211. })
  212. document.addEventListener("touchmove",function(e){
  213. if($(".index").css("display")=="none"){
  214. e.preventDefault();//禁止滚屏;
  215. };
  216. topy=parseInt($("#rw").css("top"));
  217. var touch=e.touches[0];
  218. movex=touch.pageX;
  219. movey=touch.pageY;
  220. $("#rw").css("left",movex-rwidth);
  221. $(".jiafen").css("left",movex+rwidth*1 )
  222. //设置人物跳跃
  223. //if(movey-stary<15){
  224. // topy=wheight-rheight-30;
  225. // $("#rw").css("top",topy);
  226. // }
  227. // if(movey-stary>15)
  228. // {
  229. // topy=wheight-rheight;
  230. // $("#rw").css("top",topy);
  231. // }
  232. })
  233. }
  234. //游戏开始事件
  235. $(".start").click(function(){
  236. $(".index").animate({left:"-100%"},800,function(){$(".index").css("display","none");})
  237. $("#play").css("display","none");
  238. start();
  239. })
  240. //游戏规则弹出与关闭
  241. $("#gamegz").click(function(){
  242. clickMore();
  243. });
  244. $("#fh").click(function(){
  245. $("#gamesgztc").addClass("my02").removeClass("my01");
  246. setTimeout(function(){$("#gamesgztc").css("display","none")},500)
  247. });
  248. //游戏暂停
  249. $("#startzt").click(function(){$("#gameszt").css("display","block")});
  250. $("#fhgames").click(function(){$("#gameszt").css("display","none")});
  251. //返回首页和返回游戏
  252. $(".fhsy").click(function(){
  253. //执行初始化
  254. res();
  255. //回到首页
  256. $(".index").css("display","block").animate({left:0},800);
  257. $(".gamesjs").css("display","none");
  258. $("#play").css("display","block");
  259. });
  260. $(".zlyc,#fenxiang").click(function(){
  261. //初始化
  262. res();
  263. $(".gamesjs").css("display","none");
  264. start();
  265. });
  266. //游戏暂停
  267. /*$("#startzt").click(function(){
  268. clearInterval(time1);
  269. clearInterval(time2);
  270. $("#gameszt").css("display","block").addClass("suoxiao").removeClass("fd");
  271. $("#audio")[0].pause();
  272. });*/
  273. //游戏暂停菜单
  274. //初始化方法
  275. function res(){
  276. //数据初始化
  277. isover=false;
  278. starx=null;
  279. stary=null;
  280. movex=null;
  281. movey=null;
  282. time=1500;//计时器重置
  283. times=2000;
  284. clearInterval(time1);
  285. clearInterval(time2);
  286. fenshu=0;
  287. shijian=90;
  288. $("#fenshu").text(fenshu);
  289. $("#shijian").text(shijian);
  290. $("#img p").css({"top":"50px"});
  291. $(".gamesjs ul").css("display","none");
  292. $(".gamesjs .u1").css("display","block");
  293. $("#audio")[0].play();
  294. $("#play").addClass("xuan");
  295. topyy=wheight-rheight-20;//人物跳跃
  296. }
  297. //音乐控件
  298. $("#play").toggle(function(){$("#audio")[0].pause();
  299. $("#play").removeClass("xuan");
  300. },function(){$("#audio")[0].play();
  301. $("#play").addClass("xuan");
  302. })
  303. $("#lingqu").click(function(){
  304. dp_share();
  305. });
  306. $("#more").click(function(){
  307. clickMore();
  308. });
  309. }
  310. )