123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- // 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=[],rightCount=[],time=0,hasQuestion=false,//第一个字的位置
- timer=null,//定时器
- times=0,//定时器次数
- hasClear=false,//是否有清空位置
- targetLen='',//目标元素的位置
- count1=0;
- var allCount=0;//总次数
- var targetArr=[];//存放目标位置中的答案
- $().ready(function(){
- // 先获取次数
- // 答对之后根据接口获取金豆数,重新获得次数
- getToken();
- })
- 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(885,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;
- }
- var stopCheck=false;
- $(".options li").removeClass("flick");
- $(".target li").eq(0).removeClass("blackColor");
- $(".option li").eq(0).attr("style","opacity:1");
- clearInterval(timer);
- time=1000;
- times=0;
- // 先去存放到数组中
- $(".active li").eq(index).addClass("move");
- $(".active li").eq(index).siblings().removeClass("move").attr("style","");
- hasClear=getIndex();
- targetLen=hasClear===0||hasClear?hasClear:targetArr.length;
- switch(Number(targetLen)) {
- 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;
- }
- setTimeout(function(){
- time=0;
- $(".active li").eq(index).removeClass("move").attr("style","");
- $(".target li").eq(targetLen).attr("style","");
- $(".target li").eq(targetLen).text($(".active li").eq(index).text());
- if(!hasClear&&hasClear!==0) {
- targetArr.push($(".active li").eq(index).text());
- }else {
- targetArr[hasClear]=$(".active li").eq(index).text();
- }
- hasClear=false;
- if(targetArr.length==4) {
- try {
- // 每次答题切换底部广告
- taskObj.checkAd(350,260);
- }catch(e) {
- }
- // 记录答题次数
- allCount++;
- allCount=allCount==6?allCount=1:allCount;
- count1=Math.floor(Math.random()*2);
- for(var i in rightCount) {
- if(rightCount[i]!=$(".target li").eq(i).text()){
- //错误
- hasSuccess=0;
- try {
- if(allCount==5&&count1==1) {
- window.location.href=lastHref()+"/moveAgainUpload.html"
- }else {
- taskObj.new_game_done(Number(parseQueryString("id")),Number(coin),false,Number(question_id),Number(allCount));
- }
- }catch(e) {
- if(allCount==5&&count1==1) {
- window.location.href=lastHref()+"/moveAgainUpload.html"
- }else {
- taskObj.game_done(Number(parseQueryString("id")),Number(coin),false,Number(question_id));
- }
- }
- $(".options li").eq(hasQuestion).addClass(".active");
- targetArr=[];
- timer=window.setInterval(addMove,500)
- $(".target li").text("")
- return false;
- }
- }
- hasSuccess=1
- getGold();
- }
- },600)
- }
- function getIndex() {
- if(hasClear!==0||!hasClear) {
- for(var i in targetArr) {
- if(!targetArr[i]) {
- hasClear=i;
- return hasClear;
- }
- }
- }
- }
- $(".target li").on("click",function(){
- if($(this).attr("style")==""&&$(this).text()) {
- hasClear=$(".target li").index(this);
- $(this).text("");
- $(this).attr("style","opacity:0");
- targetArr[hasClear]=""
- }
- })
- // 突出答案
- function addMove(){
- if(times<=10) {
- $(".options li").eq(hasQuestion).toggleClass("flick");
- $(".target li").eq(0).attr("style","opacity:1").toggleClass("blackColor");
- $(".option li").eq(0).attr("style","opacity:0");
- times++;
- }else {
- $(".options li").eq(hasQuestion).removeClass("flick");
- $(".target li").eq(0).removeClass("blackColor");
- $(".option li").eq(0).attr("style","opacity:1");
- clearInterval(timer);
- }
- }
- function init() {
- liArr=[]
- newArr=[]
- target=[]
- targetArr=[]
- rightCount=[]
- 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="";
- hasQuestion=false;
- if(!hasHide) {
- for(var i in res.words) {
- liArr+='<li>'+res.words[i]+'</li>'
- newArr+='<li onclick="checkWord('+i+')">'+res.words[i]+'</li>'
- $(".target li").attr("style","");
- if(!hasQuestion) {
- if(res.wordOne==res.words[i]) {
- hasQuestion=i;
- }
- }
- }
- $(".target li").eq(0).text(res.wordOne).attr("style","opacity:0")
- $(".target li").eq(1).text(res.wordTwo).attr("style","opacity:0")
- $(".target li").eq(2).text(res.wordThree).attr("style","opacity:0")
- $(".target li").eq(3).text(res.wordFour).attr("style","opacity:0")
- $(".options ul").html(liArr)
- $(".active").html(newArr)
- 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)
- try {
- if(allCount==5&&count1==1) {
- window.location.href=lastHref()+"/moveAgainUpload.html"
- }else {
- taskObj.new_game_done(Number(parseQueryString("id")),Number(res.res.coin),true,Number(question_id),Number(allCount))
- }
- }catch(e) {
- if(allCount==5&&count1==1) {
- window.location.href=lastHref()+"/moveAgainUpload.html"
- }else {
- 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<vars.length;i++) {
- var pair = vars[i].split("=");
- if(pair[0] == variable){return pair[1];}
- }
- return(false);
- }
- function lastHref() {
- var test=window.location.pathname;
- var newTest=test.split("/")
- var test1=newTest[newTest.length-1];
- return window.location.origin+test.replace("/"+test1,"")
- }
- // 随机数
- function rnd(n, m, x) {
- var random = Math.floor(Math.random() * (m - n + 1) + n);
- if(x==random) {
- rnd(n,m,x);
- return false;
- }else {
- return random;
- }
- }
|