No Description

newCrossWord.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. // var cid='1002',imei='352936095523931',androidId='6c735b635fe943c852e8392152f20ac8',version='1.5.4',secretkey='3d0e4b94e04b8dcca1cedb9c33051173',goldCount='',gameId='',hasHide=false,emptyPosition=''//空位置
  2. var cid='',imei='',androidId='',version='',secretkey='3d0e4b94e04b8dcca1cedb9c33051173',goldCount='',gameId='',hasHide=false,emptyPosition='';//空位置
  3. var question_id='',coin='',hasSuccess=0,item='',liArr=[],newArr=[],target=[],rightCount=[],time=0,hasQuestion=false,//第一个字的位置
  4. timer=null,//定时器
  5. times=0,//定时器次数
  6. hasClear=false,//是否有清空位置
  7. targetLen='',//目标元素的位置
  8. count1=0;
  9. var allCount=0;//总次数
  10. var targetArr=[];//存放目标位置中的答案
  11. $().ready(function(){
  12. // 先获取次数
  13. // 答对之后根据接口获取金豆数,重新获得次数
  14. getToken();
  15. })
  16. function getToken() {
  17. try {
  18. var data=JSON.parse(taskObj.jsGetToken());
  19. cid=data.cid,imei=data.imei,androidId=data.androidId,version=data.version,token=data.token
  20. // 获取金币
  21. init();
  22. }catch(e) {
  23. token = 'e094ced38ef917b5219bd5a4f79c261011855563'
  24. init();
  25. }
  26. adSize();//添加广告位(新版本上线后提)
  27. }
  28. // 广告
  29. function adSize(){
  30. taskObj.onLayoutAdSize(885,350,260,20)
  31. }
  32. function showRule() {
  33. $(".mask").show();
  34. $(".rule_content").show();
  35. $("body").attr("style","overflow:hidden");
  36. }
  37. $("button").on("click",function(){
  38. $(".mask").hide();
  39. $(".rule_content").hide();
  40. $("body").attr("style","");
  41. })
  42. function checkWord(index) {
  43. if(time != 0 ){
  44. return;
  45. }
  46. var stopCheck=false;
  47. $(".options li").removeClass("flick");
  48. $(".target li").eq(0).removeClass("blackColor");
  49. $(".option li").eq(0).attr("style","opacity:1");
  50. clearInterval(timer);
  51. time=1000;
  52. times=0;
  53. // 先去存放到数组中
  54. $(".active li").eq(index).addClass("move");
  55. $(".active li").eq(index).siblings().removeClass("move").attr("style","");
  56. hasClear=getIndex();
  57. targetLen=hasClear===0||hasClear?hasClear:targetArr.length;
  58. switch(Number(targetLen)) {
  59. case 0:
  60. $(".move").attr("style","left:.43rem");
  61. break;
  62. case 1:
  63. $(".move").attr("style","left:1.18rem");
  64. break;
  65. case 2:
  66. $(".move").attr("style","left:1.93rem");
  67. break;
  68. default:
  69. $(".move").attr("style","left:2.68rem");
  70. break;
  71. }
  72. setTimeout(function(){
  73. time=0;
  74. $(".active li").eq(index).removeClass("move").attr("style","");
  75. $(".target li").eq(targetLen).attr("style","");
  76. $(".target li").eq(targetLen).text($(".active li").eq(index).text());
  77. if(!hasClear&&hasClear!==0) {
  78. targetArr.push($(".active li").eq(index).text());
  79. }else {
  80. targetArr[hasClear]=$(".active li").eq(index).text();
  81. }
  82. hasClear=false;
  83. if(targetArr.length==4) {
  84. try {
  85. // 每次答题切换底部广告
  86. taskObj.checkAd(350,260);
  87. }catch(e) {
  88. }
  89. // 记录答题次数
  90. allCount++;
  91. allCount=allCount==6?allCount=1:allCount;
  92. count1=Math.floor(Math.random()*2);
  93. for(var i in rightCount) {
  94. if(rightCount[i]!=$(".target li").eq(i).text()){
  95. //错误
  96. hasSuccess=0;
  97. try {
  98. if(allCount==5&&count1==1) {
  99. window.location.href=lastHref()+"/moveAgainUpload.html"
  100. }else {
  101. taskObj.new_game_done(Number(parseQueryString("id")),Number(coin),false,Number(question_id),Number(allCount));
  102. }
  103. }catch(e) {
  104. if(allCount==5&&count1==1) {
  105. window.location.href=lastHref()+"/moveAgainUpload.html"
  106. }else {
  107. taskObj.game_done(Number(parseQueryString("id")),Number(coin),false,Number(question_id));
  108. }
  109. }
  110. $(".options li").eq(hasQuestion).addClass(".active");
  111. targetArr=[];
  112. timer=window.setInterval(addMove,500)
  113. $(".target li").text("")
  114. return false;
  115. }
  116. }
  117. hasSuccess=1
  118. getGold();
  119. }
  120. },600)
  121. }
  122. function getIndex() {
  123. if(hasClear!==0||!hasClear) {
  124. for(var i in targetArr) {
  125. if(!targetArr[i]) {
  126. hasClear=i;
  127. return hasClear;
  128. }
  129. }
  130. }
  131. }
  132. $(".target li").on("click",function(){
  133. if($(this).attr("style")==""&&$(this).text()) {
  134. hasClear=$(".target li").index(this);
  135. $(this).text("");
  136. $(this).attr("style","opacity:0");
  137. targetArr[hasClear]=""
  138. }
  139. })
  140. // 突出答案
  141. function addMove(){
  142. if(times<=10) {
  143. $(".options li").eq(hasQuestion).toggleClass("flick");
  144. $(".target li").eq(0).attr("style","opacity:1").toggleClass("blackColor");
  145. $(".option li").eq(0).attr("style","opacity:0");
  146. times++;
  147. }else {
  148. $(".options li").eq(hasQuestion).removeClass("flick");
  149. $(".target li").eq(0).removeClass("blackColor");
  150. $(".option li").eq(0).attr("style","opacity:1");
  151. clearInterval(timer);
  152. }
  153. }
  154. function init() {
  155. liArr=[]
  156. newArr=[]
  157. target=[]
  158. targetArr=[]
  159. rightCount=[]
  160. var time1=new Date().getTime();
  161. sign=md5("time="+time1+secretkey)
  162. $.ajax({
  163. type: 'post',
  164. url: '/api/V3/getQuestion',
  165. headers:{
  166. cid:cid,//渠道号暂时写死
  167. version:version,
  168. imei:imei,
  169. time:time1,
  170. sign:sign,
  171. token:token,
  172. androidId:androidId
  173. },
  174. success: function (res) {
  175. var res=JSON.parse(res)
  176. if(res&&res.code==0) {
  177. var res=res.res
  178. $(".pict").attr("src",res.imgUrl)
  179. question_id=res.idiomId
  180. if(!coin) {
  181. initGold();
  182. }
  183. rightCount = [res.wordOne,res.wordTwo,res.wordThree,res.wordFour]
  184. item=rnd(1,4,res.emptyPosition)
  185. do {
  186. item=rnd(1,4,res.emptyPosition)
  187. } while (!item);
  188. liArr="";
  189. newArr="";
  190. hasQuestion=false;
  191. if(!hasHide) {
  192. for(var i in res.words) {
  193. liArr+='<li>'+res.words[i]+'</li>'
  194. newArr+='<li onclick="checkWord('+i+')">'+res.words[i]+'</li>'
  195. $(".target li").attr("style","");
  196. if(!hasQuestion) {
  197. if(res.wordOne==res.words[i]) {
  198. hasQuestion=i;
  199. }
  200. }
  201. }
  202. $(".target li").eq(0).text(res.wordOne).attr("style","opacity:0")
  203. $(".target li").eq(1).text(res.wordTwo).attr("style","opacity:0")
  204. $(".target li").eq(2).text(res.wordThree).attr("style","opacity:0")
  205. $(".target li").eq(3).text(res.wordFour).attr("style","opacity:0")
  206. $(".options ul").html(liArr)
  207. $(".active").html(newArr)
  208. emptyPosition=res.emptyPosition-1;
  209. }
  210. }
  211. },
  212. error: function () {
  213. showMsg('网络错误,请稍后再试!')
  214. }
  215. })
  216. }
  217. $(".back").on("click",function() {
  218. if(hasSuccess) {
  219. var target=lastHref()+"/taskList.html?id="+parseQueryString("id")+"&question_id="+question_id
  220. taskObj.h5_back(target)
  221. }else {
  222. var target=lastHref()+"/taskList.html?id=-1"
  223. taskObj.h5_back(target)
  224. }
  225. })
  226. function initGold() {
  227. var time1=new Date().getTime();
  228. var arr=["hasSuccess="+1,"question_id="+question_id,"type="+parseQueryString("id"),"time="+time1]
  229. var sign=arr.join("&")
  230. sign=md5(sign+secretkey)
  231. $.ajax({
  232. type: 'post',
  233. url: '/api/V3/getUserAdvertStatus',
  234. headers:{
  235. token:token,
  236. cid:cid,//渠道号暂时写死
  237. imei:imei,
  238. time:time1,
  239. sign:sign,
  240. androidId:androidId
  241. },
  242. data: {
  243. type: parseQueryString("id"),
  244. hasSuccess: 1,
  245. question_id: question_id
  246. },
  247. success: function (res) {
  248. var res=JSON.parse(res)
  249. coin=res.res.coin
  250. $(".notice").text("今日剩余答题次数:"+res.res.residualCount)
  251. if(res.res.residualCount==0) {
  252. var msgBox = $('.alert-info');
  253. msgBox.children('p').text("今日游戏次数已用完,明日再来吧");
  254. msgBox.show();
  255. }
  256. },
  257. error: function () {
  258. showMsg('网络错误,请稍后再试!')
  259. }
  260. })
  261. }
  262. // 领取金币
  263. function getGold() {
  264. var time1=new Date().getTime();
  265. var arr=["question_id="+question_id,"type="+parseQueryString("id"),"time="+time1]
  266. var sign=arr.join("&")
  267. sign=md5(sign+secretkey)
  268. $.ajax({
  269. type: 'post',
  270. url: '/api/V3/getAdvertCoin',
  271. headers:{
  272. token:token,
  273. cid:cid,
  274. imei:imei,
  275. time:time1,
  276. sign:sign,
  277. androidId:androidId,
  278. version:version,
  279. },
  280. data:{
  281. type: parseQueryString("id"),
  282. question_id: question_id
  283. },
  284. success:function (res) {
  285. var res=JSON.parse(res)
  286. if (res && res.code==0) {
  287. init()
  288. $(".notice").text("今日剩余答题次数:"+res.res.residualCount)
  289. try {
  290. if(allCount==5&&count1==1) {
  291. window.location.href=lastHref()+"/moveAgainUpload.html"
  292. }else {
  293. taskObj.new_game_done(Number(parseQueryString("id")),Number(res.res.coin),true,Number(question_id),Number(allCount))
  294. }
  295. }catch(e) {
  296. if(allCount==5&&count1==1) {
  297. window.location.href=lastHref()+"/moveAgainUpload.html"
  298. }else {
  299. taskObj.game_done(Number(parseQueryString("id")),Number(res.res.coin),true,Number(question_id))
  300. }
  301. }
  302. }else {
  303. showMsg(res.res.msg)
  304. }
  305. },
  306. error: function () {
  307. showMsg('网络错误,请稍后再试!')
  308. }
  309. })
  310. }
  311. function parseQueryString(variable) {
  312. var query = window.location.search.substring(1);
  313. var vars = query.split("&");
  314. for (var i=0;i<vars.length;i++) {
  315. var pair = vars[i].split("=");
  316. if(pair[0] == variable){return pair[1];}
  317. }
  318. return(false);
  319. }
  320. function lastHref() {
  321. var test=window.location.pathname;
  322. var newTest=test.split("/")
  323. var test1=newTest[newTest.length-1];
  324. return window.location.origin+test.replace("/"+test1,"")
  325. }
  326. // 随机数
  327. function rnd(n, m, x) {
  328. var random = Math.floor(Math.random() * (m - n + 1) + n);
  329. if(x==random) {
  330. rnd(n,m,x);
  331. return false;
  332. }else {
  333. return random;
  334. }
  335. }