// var cid='1002',imei='352936095523931',androidId='6c735b635fe943c852e8392152f20ac8',version='1.5.4',secretkey='3d0e4b94e04b8dcca1cedb9c33051173',goldCount='',gameId='',hasHide=false,emptyPosition=''//空位置 var cid='',imei='',androidId='',version='',secretkey='3d0e4b94e04b8dcca1cedb9c33051173',goldCount='',gameId='',hasHide=false,emptyPosition=''//空位置 var question_id='',coin='',hasSuccess=0,item='',liArr=[],newArr=[],target=[],targetArr=[],newTarget='',rightCount=[],time=0; $().ready(function(){ // 先获取次数 // 答对之后根据接口获取金豆数,重新获得次数 getToken(); // window.location.href="http://192.168.22.39/other/qianduo/games_h5/crossword1.html?id=8" }) function getToken() { try { var data=JSON.parse(taskObj.jsGetToken()); cid=data.cid,imei=data.imei,androidId=data.androidId,version=data.version,token=data.token // 获取金币 init(); }catch(e) { token = 'e094ced38ef917b5219bd5a4f79c261011855563' init(); } adSize();//添加广告位 } // 广告 function adSize(){ taskObj.onLayoutAdSize(925,350,260,20) } function showRule() { $(".mask").show(); $(".rule_content").show(); $("body").attr("style","overflow:hidden"); } $("button").on("click",function(){ $(".mask").hide(); $(".rule_content").hide(); $("body").attr("style",""); }) function checkWord(index) { if(time != 0 ){ return; } time=1000; $(".active li").eq(index).addClass("move"); $(".active li").eq(index).siblings().removeClass("move").attr("style","") // 接口给的值大,先选自定义的值 if(targetArr.length==0) { var newTarget=emptyPositionitem-1?emptyPosition:item-1 } if(emptyPosition>item-1) { switch(item-1) { case 0: $(".move").attr("style","left:.43rem"); break; case 1: $(".move").attr("style","left:1.18rem"); break; case 2: $(".move").attr("style","left:1.93rem"); break; default: $(".move").attr("style","left:2.68rem"); break; } item = 999; }else { switch(emptyPosition) { case 0: $(".move").attr("style","left:.43rem"); break; case 1: $(".move").attr("style","left:1.18rem"); break; case 2: $(".move").attr("style","left:1.93rem"); break; default: $(".move").attr("style","left:2.68rem"); break; } emptyPosition=999 } setTimeout(function(){ time=0; $(".target li").eq(newTarget).attr("style",""); $(".target li").eq(newTarget).text($(".active li").eq(index).text()) targetArr.push('1000') if(targetArr.length==2) { var it = ''; for(var i in rightCount) { if(rightCount[i]!=$(".target li").eq(i).text()){ //错误 hasSuccess=0; taskObj.game_done(Number(parseQueryString("id")),Number(coin),false,Number(question_id)) init(); return false; }else { hasSuccess=1; } } if(hasSuccess==1) { getGold(); } } },1000) } function init() { liArr=[] newArr=[] target=[] targetArr=[] rightCount=[] newTarget='' var time1=new Date().getTime(); sign=md5("time="+time1+secretkey) $.ajax({ type: 'post', url: '/api/V3/getQuestion', headers:{ cid:cid,//渠道号暂时写死 version:version, imei:imei, time:time1, sign:sign, token:token, androidId:androidId }, success: function (res) { var res=JSON.parse(res) if(res&&res.code==0) { var res=res.res $(".pict").attr("src",res.imgUrl) question_id=res.idiomId if(!coin) { initGold(); } rightCount = [res.wordOne,res.wordTwo,res.wordThree,res.wordFour] item=rnd(1,4,res.emptyPosition) do { item=rnd(1,4,res.emptyPosition) } while (!item); liArr="" newArr="" if(!hasHide) { for(var i in res.words) { liArr+='
  • '+res.words[i]+'
  • ' newArr+='
  • '+res.words[i]+'
  • ' $(".target li").attr("style",""); $(".target li").eq(0).text(res.wordOne) $(".target li").eq(1).text(res.wordTwo) $(".target li").eq(2).text(res.wordThree) $(".target li").eq(3).text(res.wordFour) $(".options ul").html(liArr) $(".active").html(newArr) $(".target li").eq(res.emptyPosition-1).attr("style","opacity:0"); $(".target li").eq(item-1).attr("style","opacity:0"); emptyPosition=res.emptyPosition-1 } } } }, error: function () { showMsg('网络错误,请稍后再试!') } }) } $(".back").on("click",function() { if(hasSuccess) { var target=lastHref()+"/taskList.html?id="+parseQueryString("id")+"&question_id="+question_id taskObj.h5_back(target) }else { var target=lastHref()+"/taskList.html?id=-1" taskObj.h5_back(target) } }) function initGold() { var time1=new Date().getTime(); var arr=["hasSuccess="+1,"question_id="+question_id,"type="+parseQueryString("id"),"time="+time1] var sign=arr.join("&") sign=md5(sign+secretkey) $.ajax({ type: 'post', url: '/api/V3/getUserAdvertStatus', headers:{ token:token, cid:cid,//渠道号暂时写死 imei:imei, time:time1, sign:sign, androidId:androidId }, data: { type: parseQueryString("id"), hasSuccess: 1, question_id: question_id }, success: function (res) { var res=JSON.parse(res) coin=res.res.coin $(".notice").text("今日剩余答题次数:"+res.res.residualCount) if(res.res.residualCount==0) { var msgBox = $('.alert-info'); msgBox.children('p').text("今日游戏次数已用完,明日再来吧"); msgBox.show(); } }, error: function () { showMsg('网络错误,请稍后再试!') } }) } // 领取金币 function getGold() { var time1=new Date().getTime(); var arr=["question_id="+question_id,"type="+parseQueryString("id"),"time="+time1] var sign=arr.join("&") sign=md5(sign+secretkey) $.ajax({ type: 'post', url: '/api/V3/getAdvertCoin', headers:{ token:token, cid:cid, imei:imei, time:time1, sign:sign, androidId:androidId, version:version, }, data:{ type: parseQueryString("id"), question_id: question_id }, success:function (res) { var res=JSON.parse(res) if (res && res.code==0) { init() $(".notice").text("今日剩余答题次数:"+res.res.residualCount) taskObj.game_done(Number(parseQueryString("id")),Number(res.res.coin),true,Number(question_id)) }else { showMsg(res.res.msg) } }, error: function () { showMsg('网络错误,请稍后再试!') } }) } function parseQueryString(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i