123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- // 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=emptyPosition<item-1?emptyPosition:item-1
- }else {
- newTarget=emptyPosition>item-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+='<li>'+res.words[i]+'</li>'
- newArr+='<li onclick="checkWord('+i+')">'+res.words[i]+'</li>'
- $(".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<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;
- }
- }
|