ygjDefault.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. window.scrollTo(0, 1);
  2. var gameW = 320;
  3. var gameH = 400;
  4. var static_gameW = 320;
  5. var static_gameH = 400;
  6. var menu;
  7. var menuItems;
  8. var canvas;
  9. var context;
  10. var cursorX;
  11. var cursorY;
  12. var imgUrl = "";
  13. var lineLink = "";
  14. var descContent = '';
  15. var shareTitle = '';
  16. var appid = '';
  17. var ygjscore = 1000;
  18. var ygjscoreunit = "秒";
  19. var mode2LevelNum = "A1";
  20. var stepLeft = 1;
  21. var levels = [
  22. [//1
  23. [[88,94],[203,139],[85,214],[203,268]],
  24. [[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]]
  25. ],
  26. [//2
  27. [[163,96],[230,315],[53,233],[244,121],[133,324]],
  28. [[0,1],[0,2],[0,3],[0,4],[1,3],[2,3],[3,4]]
  29. ],
  30. [//3
  31. [[237,296],[85,278],[153,71],[48,148],[268,151],[161,332]],
  32. [[0,2],[1,2],[1,3],[1,4],[2,3],[2,4],[2,5],[3,4],[4,5]]
  33. ],
  34. [//4
  35. [[247,102],[147,91],[156,281],[56,180],[68,214],[239,260]],
  36. [[0,2],[0,4],[0,5],[1,2],[1,4],[1,5],[2,4],[3,5]]
  37. ],
  38. [//5
  39. [[109,335],[286,183],[50,273],[180,80],[63,134],[253,314]],
  40. [[0,1],[0,3],[1,3],[1,4],[2,3],[2,4],[3,4],[3,5],[4,5]]
  41. ],
  42. [//6
  43. [[235,291],[182,57],[54,258],[249,114],[199,260],[69,112]],
  44. [[0,1],[0,2],[0,3],[1,2],[1,4],[1,5],[2,3],[2,4],[2,5],[3,5],[4,5]]
  45. ],
  46. [//7
  47. [[78,265],[237,105],[202,296],[268,246],[126,60],[63,116]],
  48. [[0,1],[0,2],[0,3],[0,4],[0,5],[1,2],[1,5],[2,3],[2,4],[2,5],[3,4]]
  49. ],
  50. [//8
  51. [[123,295],[204,296],[259,213],[55,222],[207,101],[89,117]],
  52. [[0,1],[0,2],[0,5],[1,4],[1,5],[2,3],[2,4],[2,5],[3,4],[4,5]]
  53. ],
  54. [//9
  55. [[61,99],[256,276],[36,207],[107,303],[196,336],[236,78],[264,182],[170,170]],
  56. [[0,1],[0,2],[0,4],[0,6],[0,7],[1,3],[2,3],[2,4],[2,5],[2,6],[2,7],[3,5],[3,6],[5,7]]
  57. ],
  58. [//10
  59. [[154,255],[186,191],[85,279],[49,167],[198,93],[264,178],[108,111],[251,298]],
  60. [[0,5],[0,6],[1,2],[1,4],[1,7],[2,3],[2,4],[2,6],[2,7],[3,6],[3,7],[4,6],[4,7],[5,6]]
  61. ],
  62. [//11
  63. [[179,196],[84,124],[61,276],[223,295],[277,144],[49,172],[200,132],[131,347],[160,60],[257,208]],
  64. [[0,2],[1,2],[1,6],[2,3],[2,9],[3,5],[4,6],[4,7],[5,9],[6,9],[7,8]]
  65. ],
  66. [//12
  67. [[35,169],[169,336],[219,208],[280,233],[256,305],[154,78],[94,314]],
  68. [[0,1],[0,2],[0,6],[1,2],[1,3],[1,5],[2,5],[2,6],[3,4],[3,5],[4,6],[5,6]]
  69. ],
  70. [//13
  71. [[272,173],[94,93],[204,62],[87,260],[240,268],[50,163],[168,346],[173,198]],
  72. [[0,5],[0,6],[0,7],[1,3],[1,4],[1,5],[1,6],[1,7],[2,3],[2,4],[2,6],[3,4],[3,6],[3,7],[5,6],[5,7]]
  73. ],
  74. [//14
  75. [[272,200],[116,211],[241,299],[45,204],[148,84],[231,97],[51,291],[169,322]],
  76. [[0,1],[0,2],[0,4],[0,7],[1,4],[2,3],[2,5],[2,7],[3,4],[3,7],[4,5],[4,6],[4,7],[6,7]]
  77. ],
  78. [//15
  79. [[211,100],[241,143],[227,259],[159,302],[50,156],[47,225],[114,83],[107,131]],
  80. [[0,2],[0,5],[0,6],[1,5],[1,6],[2,4],[2,5],[2,6],[2,7],[3,5],[3,7],[4,6],[4,7]]
  81. ],
  82. [//16
  83. [[90,288],[229,216],[244,129],[82,102],[156,271],[190,287],[145,56],[47,204]],
  84. [[0,3],[0,5],[0,6],[0,7],[1,2],[1,5],[1,6],[1,7],[2,3],[2,4],[3,4],[4,7],[5,6]]
  85. ],
  86. [//17
  87. [[241,170],[104,290],[40,208],[141,206],[197,73],[66,122],[169,119],[216,279]],
  88. [[0,1],[0,5],[1,5],[1,7],[2,3],[2,6],[2,7],[3,6],[3,7],[4,5],[4,6],[4,7],[5,6],[6,7]]
  89. ],
  90. [//18
  91. [[213,297],[268,161],[75,315],[266,272],[100,101],[188,96],[48,224],[139,326]],
  92. [[0,1],[0,6],[0,7],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[2,4],[2,5],[3,4],[4,6],[6,7]]
  93. ],
  94. [//19
  95. [[189,184],[133,291],[157,69],[38,172],[83,114],[94,171],[229,249],[255,124]],
  96. [[0,2],[0,7],[1,3],[1,5],[1,6],[2,4],[2,5],[2,6],[3,5],[3,6],[4,5],[4,6],[5,6],[5,7],[6,7]]
  97. ],
  98. [//20
  99. [[156,186],[263,111],[75,302],[82,106],[208,317],[152,89],[254,218],[48,189]],
  100. [[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,5],[1,6],[1,7],[2,5],[2,6],[3,4],[3,5],[4,5],[5,6],[5,7],[6,7]]
  101. ]
  102. ];
  103. var TimeLevel = [
  104. [
  105. [[136,186],[243,121],[55,272],[62,106],[178,297],[132,89],[234,218],[28,189]],
  106. [[0,1],[0,2],[0,3],[0,4],[1,2],[1,3],[1,5],[1,6],[1,7],[2,5],[2,6],[3,4],[3,5],[4,5],[5,6],[5,7],[6,7]]
  107. ],
  108. [[[160,80],[160,120],[160,260],[160,315],[50,200],[120,200],[200,200],[270,200]],
  109. [[0,5],[0,6],[3,5],[3,6],[4,1],[4,2],[7,1],[7,2],[5,1],[5,2],[6,1],[6,2],[4,6],[4,7],[1,2]]
  110. ]
  111. ];
  112. var smartQuote = [
  113. "脑筋不搭牢,yeah~",
  114. "有潜力哦,我看好你哦",
  115. "我为脑筋代言",
  116. "冲杯三鹿给你喝",
  117. "脑筋搭牢是一种生活态度",
  118. "土豪一般都搭牢",
  119. "农夫三拳有点疼",
  120. "天哪!我的衣服又瘦了",
  121. "猪是的念来过倒",
  122. "三人行,必有猪头",
  123. "我想早恋,但是已经晚了",
  124. "脑筋就是生产力",
  125. "别人装逼,我装脑筋",
  126. "忍无可忍,就重新再忍",
  127. "心在移动,如何联通",
  128. "别紧张,我不是什么好人",
  129. "老子不但有车,还是自行的",
  130. "我错了,我小看你了",
  131. "脑筋很好使嘛,还有一关"
  132. ];
  133. //创建localStorage
  134. var localStorageClass = function () {
  135. this.options = {
  136. expires: 60 * 24 * 3600,
  137. domain: "game.9g.com"
  138. }
  139. }
  140. localStorageClass.prototype = {
  141. //初实化。添加过期时间
  142. init: function () {
  143. var date = new Date();
  144. date.setTime(date.getTime() + 60 * 24 * 3600);
  145. this.setItem('expires', date.toGMTString());
  146. },
  147. //内部函数 参数说明(key) 检查key是否存在
  148. findItem: function (key) {
  149. var bool = document.cookie.indexOf(key);
  150. if (bool < 0) {
  151. return true;
  152. } else {
  153. return false;
  154. }
  155. },
  156. //得到元素值 获取元素值 若不存在则返回 null
  157. getItem: function (key) {
  158. var i = this.findItem(key);
  159. if (!i) {
  160. var array = document.cookie.split(';')
  161. for (var j = 0; j < array.length; j++) {
  162. var arraySplit = array[j];
  163. if (arraySplit.indexOf(key) > -1) {
  164. var getValue = array[j].split('=');
  165. //将 getValue[0] trim删除两端空格
  166. getValue[0] = getValue[0].replace(/^\s\s*/, '').replace(/\s\s*$/, '')
  167. if (getValue[0] == key) {
  168. return getValue[1];
  169. } else {
  170. return 'null';
  171. }
  172. }
  173. }
  174. }
  175. },
  176. //重新设置元素
  177. setItem: function (key, value) {
  178. var i = this.findItem(key)
  179. document.cookie = key + '=' + value;
  180. },
  181. //清除cookie 参数一个或多一
  182. clear: function () {
  183. for (var cl = 0 ; cl < arguments.length; cl++) {
  184. var date = new Date();
  185. date.setTime(date.getTime() - 100);
  186. document.cookie = arguments[cl] + "=a; expires=" + date.toGMTString();
  187. }
  188. }
  189. }
  190. var ygjstorage = new localStorageClass();
  191. ygjstorage.init();
  192. var saveFile = ygjstorage.getItem("ygjSave");
  193. if(!saveFile) {
  194. saveFile = "0";
  195. ygjstorage.setItem("ygjSave", saveFile);
  196. }
  197. var levelNum = 1;
  198. var level = levels[levelNum-1];
  199. var mode = 0;
  200. var field;
  201. var collisions = [
  202. [0, 0, 0, 0],
  203. [false, false, false, false, false]
  204. ];
  205. var selectedCircle;
  206. var s;
  207. function setCharAt(str,index,chr) {
  208. if(index > str.length-1) return str;
  209. return str.substr(0,index) + chr + str.substr(index+1);
  210. }
  211. function init() {
  212. gameW = pageWidth()*0.95;
  213. gameH = pageHeight()-115;
  214. /*create menu*/
  215. menu = document.getElementById("menu");
  216. menuItems = [];
  217. drawSysMenu();
  218. document.title = "一根筋玩到底-9G游戏";
  219. }
  220. function drawSysMenu(){
  221. menuHeader = document.createElement("h3");
  222. menuHeader.textContent = "大家一起一根筋";
  223. menu.appendChild(menuHeader);
  224. menu = document.getElementById("menu");
  225. menuItem = document.createElement("br");
  226. menu.appendChild(menuItem);
  227. menuItem = document.createElement("div");
  228. menuItem.innerHTML = "闯关模式";
  229. menuItem.style.width="60%";
  230. menuItem.style.background="blueviolet";
  231. menuItem.onmouseup = function() {
  232. menu = document.getElementById("menu");
  233. menu.innerHTML = "";
  234. mode = 1;
  235. levelNum = saveFile + 1;
  236. drawmenu();
  237. }
  238. menu.appendChild(menuItem);
  239. menuItem = document.createElement("div");
  240. menuItem.innerHTML = "竞赛模式";
  241. menuItem.style.width="60%";
  242. menuItem.style.background="indianred";
  243. menuItem.onmouseup = function(){
  244. mode = 2;
  245. menu.innerHTML = "";
  246. drawmode2menu();
  247. showMenu();
  248. }
  249. menu.appendChild(menuItem);
  250. menuItem = document.createElement("div");
  251. menuItem.innerHTML = "怎么玩?";
  252. menuItem.style.width="60%";
  253. menuItem.style.background="chocolate";
  254. menuItem.onmouseup = function() {
  255. showOverlay();
  256. }
  257. menu.appendChild(menuItem);
  258. menuItem = document.createElement("div");
  259. menuItem.innerHTML = "更多游戏";
  260. menuItem.style.width="60%";
  261. menuItem.style.background="chocolate";
  262. menuItem.onmouseup = function() {
  263. clickMore();
  264. }
  265. menu.appendChild(menuItem);
  266. }
  267. function drawmode2menu(){
  268. menuHeader = document.createElement("h3");
  269. menuHeader.textContent = "竞赛模式";
  270. menu.appendChild(menuHeader);
  271. menuItem = document.createElement("br");
  272. menu.appendChild(menuItem);
  273. menuItem = document.createElement("div");
  274. menuItem.innerHTML = "比比第一关";
  275. menuItem.style.fontSize="22px";
  276. menuItem.style.width="40%";
  277. menuItem.style.background="indianred";
  278. menuItem.onmouseup = function(){
  279. $("#overlay4").show();
  280. $("#startcount").text("3");
  281. $("#startcount").animate({'font-size':'200px'},"normal");
  282. $("#startcount").animate({'font-size':'8px'},"normal","linear",function(){
  283. $("#startcount").text("2");
  284. });
  285. $("#startcount").animate({'font-size':'200px'},"normal");
  286. $("#startcount").animate({'font-size':'8px'},"normal","linear",function(){
  287. $("#startcount").text("1");
  288. });
  289. $("#startcount").animate({'font-size':'200px'},"normal");
  290. $("#startcount").animate({'font-size':'8px'},"normal","linear",function(){
  291. $("#overlay4").hide();
  292. document.getElementById("menuBtn").style.display = "inline";
  293. document.getElementById("menuBtn2").style.display = "none";
  294. document.getElementById("header").style.display = "none";
  295. document.getElementById("TimeClock").style.display = "block";
  296. menu.innerHTML = "";
  297. levelNum = 0;
  298. mode2LevelNum = "A1";
  299. initCanvas();
  300. startTimeLevel();
  301. });
  302. }
  303. menu.appendChild(menuItem);
  304. menuItem = document.createElement("div");
  305. menuItem.innerHTML = "排行榜";
  306. menuItem.style.width = "25%";
  307. menuItem.style.fontSize = "22px";
  308. menuItem.style.background = "rgb(210, 105, 30)";
  309. menuItem.onmouseup = function () {
  310. window.location.href = rankurl ;
  311. }
  312. menu.appendChild(menuItem);
  313. //menuItem = document.createElement("div");
  314. //menuItem.innerHTML = "比比第二关";
  315. //menuItem.style.fontSize="28px";
  316. //menuItem.style.width="60%";
  317. //menuItem.style.background="rgb(210, 105, 30)";
  318. //menuItem.onmouseup = function(){
  319. // $("#overlay4").show();
  320. // $("#startcount").text("3");
  321. // $("#startcount").animate({'font-size':'200px'},"normal");
  322. // $("#startcount").animate({'font-size':'8px'},"normal","linear",function(){
  323. // $("#startcount").text("2");
  324. // });
  325. // $("#startcount").animate({'font-size':'200px'},"normal");
  326. // $("#startcount").animate({'font-size':'8px'},"normal","linear",function(){
  327. // $("#startcount").text("1");
  328. // });
  329. // $("#startcount").animate({'font-size':'200px'},"normal");
  330. // $("#startcount").animate({'font-size':'8px'},"normal","linear",function(){
  331. // $("#overlay4").hide();
  332. // document.getElementById("menuBtn").style.display = "inline";
  333. // document.getElementById("menuBtn2").style.display = "none";
  334. // document.getElementById("header").style.display = "none";
  335. // document.getElementById("TimeClock").style.display = "block";
  336. // menu.innerHTML = "";
  337. // levelNum = 0;
  338. // mode2LevelNum = "A2";
  339. // initCanvas();
  340. // startTimeLevel();
  341. // });
  342. //}
  343. //menu.appendChild(menuItem);
  344. menuItem = document.createElement("br");
  345. menu.appendChild(menuItem);
  346. menuItem = document.createElement("br");
  347. menu.appendChild(menuItem);
  348. menuItem = document.createElement("div");
  349. menuItem.innerHTML = "更多挑战即将到来...";
  350. menuItem.style.fontSize="16px";
  351. menuItem.style.width="65%";
  352. menu.appendChild(menuItem);
  353. }
  354. var stepConfig = [1,2,3,3,3,3,3,3,5,3,3,3,6,3,3,3,2,3,3,4];
  355. function drawmenu(){
  356. menuHeader = document.createElement("h3");
  357. menuHeader.textContent = "闯关模式";
  358. menu.appendChild(menuHeader);
  359. menuItem = document.createElement("br");
  360. menu.appendChild(menuItem);
  361. menuItems = [];
  362. for(i=0; i<levels.length; i++) {
  363. menuItem = document.createElement("div");
  364. menuItem.unlocked = false;
  365. if(i<saveFile){
  366. menuItem.style.backgroundColor = "rgba(73,255,63,0.35)";
  367. menuItem.unlocked = true;
  368. } else if(i==saveFile) {
  369. menuItem.style.backgroundColor = "rgba(180,180,180,0.5)";
  370. menuItem.unlocked = true;
  371. }
  372. menuItem.innerHTML += (i+1);
  373. menuItem.mID = i;
  374. menuItem.onmouseup = function() {
  375. if(this.unlocked) {
  376. hideMenu();
  377. levelNum = this.mID+1;
  378. stepLeft = stepConfig[this.mID]+1;
  379. level = levels[levelNum-1];
  380. field = level[0];
  381. $("#gametitle").text("还剩"+stepLeft+"步!");
  382. $("#gametitle").show();
  383. initCanvas();
  384. startLevel();
  385. }
  386. };
  387. menuItems.push(menuItem);
  388. menu.appendChild(menuItem);
  389. }
  390. /*menu created*/
  391. field = level[0];
  392. showMenu();
  393. document.getElementById("menuBtn2").style.display = "inline";
  394. }
  395. function initCanvas(){
  396. cursorX = 0;
  397. cursorY = 0;
  398. if(!canvas) {
  399. canvas = document.createElement("canvas");
  400. context = canvas.getContext("2d");
  401. canvas.width = gameW;
  402. canvas.height = gameH;
  403. document.getElementById('canvasdiv').appendChild(canvas);
  404. } else {
  405. context.clearRect(0,0,gameW,gameH);
  406. }
  407. if(checkForTouch()) {
  408. canvas.addEventListener('touchmove', touchMove, false);
  409. canvas.addEventListener('touchstart', touchStart, false);
  410. canvas.addEventListener('touchend', touchEnd, false);
  411. } else {
  412. canvas.addEventListener('mousemove', mouseMove, false);
  413. canvas.addEventListener('mousedown', mouseDown, false);
  414. canvas.addEventListener('mouseup', mouseUp, false);
  415. //document.body.addEventListener('keydown', keyDown, false);
  416. }
  417. scroller = {};
  418. scroller.i = 3;
  419. scroller.timer = setInterval(autoScroll, 100);
  420. canvas.style.display = "inline-block";
  421. }
  422. function clearCanvas(){
  423. canvas.style.display = "none";
  424. context.clearRect(0,0,gameW,gameH);
  425. }
  426. function clearEvents(){
  427. if(checkForTouch()) {
  428. canvas.removeEventListener('touchmove', touchMove, false);
  429. canvas.removeEventListener('touchstart', touchStart, false);
  430. canvas.removeEventListener('touchend', touchEnd, false);
  431. } else {
  432. canvas.removeEventListener('mousemove', mouseMove, false);
  433. canvas.removeEventListener('mousedown', mouseDown, false);
  434. canvas.removeEventListener('mouseup', mouseUp, false);
  435. //document.body.addEventListener('keydown', keyDown, false);
  436. }
  437. }
  438. function moveCircle() {
  439. if(typeof selectedCircle === 'undefined')
  440. return;
  441. field[selectedCircle][0] = cursorX;
  442. field[selectedCircle][1] = cursorY;
  443. draw();
  444. }
  445. function selectCircle() {
  446. if(mode==1)
  447. level = levels[levelNum-1];
  448. selectedCircle = undefined;
  449. var x;
  450. var y;
  451. var xdis;
  452. var ydis;
  453. var dis;
  454. var minDis = 100*100;
  455. for(var i=0; i<field.length; i++) {
  456. x = field[i][0];
  457. y = field[i][1];
  458. xdis = x-cursorX;
  459. ydis = y-cursorY;
  460. dis = xdis*xdis + ydis*ydis;
  461. if(dis<minDis) {
  462. minDis = dis;
  463. selectedCircle = i;
  464. }
  465. }
  466. }
  467. function startLevel() {
  468. window.scrollTo(0, 1);
  469. level = levels[levelNum-1];
  470. field = [];
  471. var angel = Math.random() * ( Math.PI*2)-Math.PI;
  472. for(i=0; i<level[0].length; i++) {
  473. point = rotate(angel, convertXLocation(level[0][i][0]),convertYLocation(level[0][i][1]));
  474. field.push([ point.x, point.y ]);
  475. }
  476. collisionMagic();
  477. setTimeout(draw,50);
  478. setTimeout(draw,100);
  479. selectedCircle=undefined;
  480. //window.location.hash = levelNum;
  481. }
  482. var startTime;
  483. var timecount = 0;
  484. var timecountover = true;
  485. function startTimeLevel() {
  486. window.scrollTo(0, 1);
  487. if(mode2LevelNum=="A1")
  488. level = TimeLevel[0];
  489. else if(mode2LevelNum=="A2")
  490. level = TimeLevel[1];
  491. field = [];
  492. var angel = Math.random() * ( Math.PI*2)-Math.PI;
  493. for(i=0; i<level[0].length; i++) {
  494. point = rotate(angel, convertXLocation(level[0][i][0]),convertYLocation(level[0][i][1]));
  495. field.push([ point.x, point.y ]);
  496. }
  497. collisionMagic();
  498. setTimeout(draw,50);
  499. setTimeout(draw,100);
  500. selectedCircle=undefined;
  501. //window.location.hash = "TimeMode";
  502. startTime=new Date().getTime();
  503. timecountover = false;
  504. timecount = 0;
  505. setTimeout(timedCount,10);
  506. }
  507. function timedCount(){
  508. if(!timecountover){
  509. timecount++;
  510. startTimeArry=(timecount/100).toString().split(".");
  511. if(startTimeArry.length==1)
  512. startTimeArry.push("00");
  513. if(startTimeArry[1].length == 1)
  514. startTimeArry[1] = startTimeArry[1]+"0";
  515. else if(startTimeArry[1].length==2)
  516. startTimeArry[1] = startTimeArry[1];
  517. else
  518. startTimeArry[1] = "00";
  519. document.getElementById("TimeSpan").innerHTML = startTimeArry[0]+"."+startTimeArry[1];
  520. var offset = new Date().getTime() - (startTime + timecount * 10);
  521. var nextTime = 10 - offset;
  522. if (nextTime < 0)
  523. nextTime = 0;
  524. setTimeout(timedCount, nextTime);
  525. }
  526. }
  527. function showMenu() {
  528. window.location.hash = "";
  529. menu.style.display = "block";
  530. document.getElementById("TimeClock").style.display = "none";
  531. document.getElementById("menuBtn").style.display = "none";
  532. document.getElementById("menuBtn2").style.display = "inline";
  533. document.getElementById("header").style.display = "block";
  534. $("#gametitle").hide();
  535. if(canvas){
  536. clearEvents();
  537. clearCanvas();
  538. }
  539. if(levelNum==0){
  540. document.getElementById("TimeClock").style.display = "none";
  541. drawmode2menu();
  542. }
  543. if(pageHeight()<500)
  544. {
  545. $("#header").hide();
  546. }
  547. else{
  548. $("#header").show();
  549. }
  550. }
  551. function showMenu2() {
  552. window.location.hash = "";
  553. menu.innerHTML = "";
  554. drawSysMenu();
  555. if(mode==2){
  556. menu.style.display = "block";
  557. timecountover = true;
  558. }
  559. document.getElementById("menuBtn2").style.display = "none";
  560. //canvas.style.display = "none";
  561. document.getElementById("header").style.display = "block";
  562. }
  563. function hideMenu() {
  564. menu.style.display = "none";
  565. if(mode==1){
  566. document.getElementById("menuBtn").style.display = "inline";
  567. document.getElementById("menuBtn2").style.display = "none";
  568. }
  569. else{
  570. document.getElementById("menuBtn").style.display = "none";
  571. document.getElementById("menuBtn2").style.display = "inline";
  572. }
  573. //canvas.style.display = "inline-block";
  574. document.getElementById("header").style.display = "none";
  575. }
  576. function winLevel() {
  577. if(mode==1){
  578. if(levelNum>saveFile)
  579. ygjstorage.setItem("ygjSave", levelNum);
  580. saveFile = ygjstorage.getItem("ygjSave")
  581. for(i=0; i<levels.length; i++) {
  582. menuItem = menuItems[i];
  583. if(i<saveFile){
  584. menuItem.style.backgroundColor = "rgba(73,255,63,0.35)";
  585. menuItem.unlocked = true;
  586. }
  587. else if(i==saveFile){
  588. menuItem.style.backgroundColor = "rgba(180,180,180,0.5)";
  589. menuItem.unlocked = true;
  590. }
  591. }
  592. continueGame();
  593. //dp_submitScore();
  594. }
  595. if(mode==2){
  596. timecountover = true;
  597. ygjscore = $("#TimeSpan").text();
  598. ygjscoreunit = "秒";
  599. //continueMode2();
  600. dp_submitScore();
  601. }
  602. }
  603. function lostLevel() {
  604. // alert("闯关失败!搭牢不要紧,只要一根筋。加油!");
  605. // continueGame();
  606. dp_submitScore();
  607. }
  608. function collisionMagic() {
  609. collisions = [
  610. [],
  611. []
  612. ];
  613. for(i=0; i<field.length; i++) {
  614. collisions[0].push(0);
  615. }
  616. for(i=0; i<level[1].length; i++) {
  617. collisions[1].push(0);
  618. }
  619. B = false;
  620. for(var i=0; i<level[1].length; i++) {
  621. for(var j=i; j<level[1].length; j++) {
  622. if(i!==j) {
  623. var b = checkCollision(level[1][i],level[1][j]);
  624. if(b) {
  625. B = true;
  626. collisions[0][level[1][i][0]]+=b;
  627. collisions[0][level[1][j][0]]+=b;
  628. collisions[0][level[1][i][1]]+=b;
  629. collisions[0][level[1][j][1]]+=b;
  630. collisions[1][i] += b;
  631. collisions[1][j] += b;
  632. }
  633. }
  634. }
  635. }
  636. if(!B) {
  637. winLevel();
  638. }
  639. else if(mode==1 && stepLeft==1){
  640. lostLevel();
  641. }
  642. else if(mode==1)
  643. {
  644. stepLeft = stepLeft - 1;
  645. $("#gametitle").text("还剩"+stepLeft+"步!");
  646. }
  647. }
  648. function checkCollision(L1, L2) {
  649. var v1 = {
  650. p0: {x: field[L1[0]][0], y: field[L1[0]][1]},
  651. p1: {x: field[L1[1]][0], y: field[L1[1]][1]},
  652. };
  653. v1.vx = v1.p0.x-v1.p1.x;
  654. v1.vy = v1.p0.y-v1.p1.y;
  655. var v2 = {
  656. p0: {x: field[L2[0]][0], y: field[L2[0]][1]},
  657. p1: {x: field[L2[1]][0], y: field[L2[1]][1]}
  658. };
  659. v2.vx = v2.p0.x-v2.p1.x;
  660. v2.vy = v2.p0.y-v2.p1.y;
  661. var tV1 = {
  662. vx:v1.p0.x-v2.p0.x,
  663. vy:v1.p0.y-v2.p0.y
  664. };
  665. var tV2 = {
  666. vx: v2.p0.x-v1.p0.x,
  667. vy: v2.p0.y-v1.p0.y
  668. }
  669. var t1 = perP(tV1, v1)/perP(v2, v1);
  670. var t2 = perP(tV2, v2)/perP(v1, v2);
  671. return(t1>-1 && t1<0 && t2>-1 && t2<0);
  672. }
  673. function perP(va, vb) {
  674. return va.vx*vb.vy - va.vy*vb.vx;
  675. }
  676. function clear() {
  677. //canvas.width = canvas.width; //prefered but buggy in desktop safari
  678. context.clearRect(0,0,gameW,gameH);
  679. }
  680. function draw() {
  681. clear();
  682. var x;
  683. var y;
  684. var c0;
  685. var c1;
  686. /*draw lines*/
  687. context.lineWidth = 2;
  688. for(var i=0; i<level[1].length; i++) {
  689. c0 = field[level[1][i][0]];
  690. c1 = field[level[1][i][1]];
  691. if(collisions[1][i]>1) {
  692. context.strokeStyle = "rgb(185,24,14)";
  693. } else if(collisions[1][i]==1) {
  694. context.strokeStyle = "rgb(235,170,34)";
  695. } else {
  696. context.strokeStyle = "rgb(7,195,13)";
  697. }
  698. context.beginPath();
  699. context.moveTo(c0[0], c0[1]);
  700. context.lineTo(c1[0], c1[1]);
  701. context.closePath();
  702. context.stroke();
  703. }
  704. /*draw circles*/
  705. for(var i=0; i<field.length; i++) {
  706. x = field[i][0];
  707. y = field[i][1];
  708. context.fillStyle = "rgb(100,100,100)";
  709. drawCirclePath(17,x,y);
  710. context.fill();
  711. if(collisions[0][i]>1) {
  712. context.fillStyle = "rgb(185,24,14)";
  713. } else if(collisions[0][i]==1) {
  714. context.fillStyle = "rgb(235,170,34)";
  715. } else {
  716. context.fillStyle = "rgb(7,195,13)";
  717. }
  718. drawCirclePath(8,x,y);
  719. context.fill();
  720. }
  721. }
  722. function convertXLocation(point){
  723. return Math.floor((point/static_gameW)*gameW);
  724. }
  725. function convertYLocation(point){
  726. return Math.floor((point/static_gameH)*gameH);
  727. }
  728. function rotate(angel, oX, oY){
  729. var point = new Object();
  730. centerX = gameW/2;
  731. centerY = gameH/2;
  732. point.x = Math.floor(((oX-centerX)*Math.cos(angel) - (oY-centerY)*Math.sin(angel))+centerX);
  733. point.y = Math.floor(((oY-centerY)*Math.cos(angel) + (oX-centerX)*Math.sin(angel))+centerY);
  734. return point;
  735. }
  736. function drawCirclePath(R,X,Y) {
  737. context.beginPath();
  738. context.arc(X,Y,R,0, Math.PI*2, true);
  739. context.closePath();
  740. }
  741. function checkForTouch() {
  742. detective = document.createElement("div");
  743. detective.setAttribute("ontouchmove", "return;");
  744. return typeof detective.ontouchmove == "function" ? true : false;
  745. }
  746. function updateCursorPos(touch) {
  747. cursorX = touch.pageX-canvas.offsetLeft;
  748. cursorY = touch.pageY-canvas.offsetTop;
  749. if(cursorX>gameW) {
  750. cursorX = gameW;
  751. } else if(cursorX<0) {
  752. cursorX = 0;
  753. }
  754. if(cursorY>gameH) {
  755. cursorY = gameH;
  756. } else if(cursorY<0) {
  757. cursorY = 0;
  758. }
  759. }
  760. function touchStart(event) {
  761. updateCursorPos(event.touches[0]);
  762. selectCircle();
  763. moveCircle();
  764. window.scrollTo(0, 1);
  765. if(cursorY>40 || cursorX<230) {
  766. event.preventDefault();
  767. }
  768. }
  769. function touchMove(event) {
  770. updateCursorPos(event.touches[0]);
  771. moveCircle();
  772. }
  773. function touchEnd(event) {
  774. selectedCircle = undefined;
  775. collisionMagic();
  776. draw();
  777. }
  778. function mouseDown(event) {
  779. updateCursorPos(event);
  780. selectCircle();
  781. moveCircle();
  782. }
  783. function mouseUp(event) {
  784. selectedCircle = undefined;
  785. collisionMagic();
  786. draw();
  787. }
  788. function mouseMove(event) {
  789. updateCursorPos(event);
  790. moveCircle();
  791. }
  792. function keyDown() {
  793. s = "[";
  794. for(i=0; i<level[0].length; i++) {
  795. s+="[";
  796. for(j=0; j<level[0][i].length; j++) {
  797. s += level[0][i][j];
  798. if(j<level[0][i].length-1) {
  799. s += ",";
  800. }
  801. }
  802. s += "]";
  803. if(i<level[0].length-1) {
  804. s += ",";
  805. }
  806. }
  807. s+="],\n["
  808. for(i=0; i<level[1].length; i++) {
  809. s+="[";
  810. for(j=0; j<level[1][i].length; j++) {
  811. s += level[1][i][j];
  812. if(j<level[1][i].length-1) {
  813. s += ",";
  814. }
  815. }
  816. s += "]";
  817. if(i<level[1].length-1) {
  818. s += ",";
  819. }
  820. }
  821. s+="]";
  822. alert(s);
  823. }
  824. function autoScroll() {
  825. window.scrollTo(0, 1);
  826. scroller.i--;
  827. if(scroller.i<0) {
  828. clearInterval(scroller.timer);
  829. scroller.timer = null;
  830. }
  831. }
  832. function showOverlay() {
  833. $("#overlay").height(pageHeight());
  834. $("#overlay").width(pageWidth());
  835. $("#overlay").fadeTo(200, 1);
  836. }
  837. function hideOverlay() {
  838. $("#overlay").fadeOut(200);}
  839. function showShare(){
  840. $("#share").show();
  841. }
  842. function showShare2(){
  843. $("#share").show();
  844. }
  845. function pageHeight() {
  846. return $(window).height();}
  847. function pageWidth() {
  848. return $(window).width();}
  849. var mebtnopenurl = 'http://web10.916d.com';
  850. var rankurl = 'http://web10.916d.com/games/ygj/index.html';
  851. window.shareData = {
  852. "imgUrl": "http://web10.916d.com/games/ygj/resources/logo_small.jpg",
  853. "timeLineLink": "http://web10.916d.com/games/ygj/index.html",
  854. "tTitle": "一根筋玩到底-viying001",
  855. "tContent": "你今天一根筋了吗?根本停不下来啊!"
  856. };
  857. function goHome() {
  858. window.location = mebtnopenurl;
  859. }
  860. function clickMore(){
  861. if((window.location+"").indexOf("zf",1)>0){
  862. window.location = "http://web10.916d.com/games/ygj/index.html";
  863. }
  864. else{
  865. goHome();
  866. }
  867. }
  868. function dp_Ranking() {
  869. window.location = rankurl;
  870. }
  871. function showAd() {
  872. }
  873. function hideAd() {
  874. }
  875. document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
  876. WeixinJSBridge.on('menu:share:appmessage', function (argv) {
  877. WeixinJSBridge.invoke('sendAppMessage', {
  878. "img_url": window.shareData.imgUrl,
  879. "link": window.shareData.timeLineLink,
  880. "desc": window.shareData.tContent,
  881. "title": window.shareData.tTitle
  882. }, onShareComplete);
  883. });
  884. WeixinJSBridge.on('menu:share:timeline', function (argv) {
  885. WeixinJSBridge.invoke('shareTimeline', {
  886. "img_url": window.shareData.imgUrl,
  887. "img_width": "64",
  888. "img_height": "64",
  889. "link": window.shareData.timeLineLink,
  890. "desc": window.shareData.tContent,
  891. "title": window.shareData.tTitle
  892. }, onShareComplete);
  893. });
  894. }, false);
  895. function continueGame(){
  896. clearCanvas();
  897. var nowYouWait = setTimeout(showMenu, 300);
  898. }
  899. function continueMode2(){
  900. clearCanvas();
  901. var nowYouWait = setTimeout(showMenu, 300);
  902. }
  903. function baiducnzz() {
  904. var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
  905. document.write(unescape("%3Cdiv%20style%3D%27display%3Anone%27%3E%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F0ae524064813b8dc07ece5ce724a7b04' type='text/javascript'%3E%3C/script%3E"));
  906. var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
  907. document.write(unescape("%3Cspan id='cnzz_stat_icon_2947366'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s5.cnzz.com/stat.php%3Fid%3D2947366' type='text/javascript'%3E%3C/script%3E%3C/div%3E"));
  908. }
  909. function dp_share() {
  910. var shareTitle = "";
  911. if (mode == 1) {
  912. if (levelNum == 20) {
  913. shareTitle = '我终于通关了,成为了伟大的一根筋!快来膜拜我吧~';
  914. }
  915. else {
  916. var percentage = levelNum * (100 / 20);
  917. shareTitle = '我一根筋冲过了第' + levelNum + '关,超越了' + percentage + '%的地球人!你的脑筋好使吗?';
  918. }
  919. }
  920. else if (mode == 2) {
  921. score = parseFloat(ygjscore);
  922. if (score > 60.0)
  923. shareTitle = "我应该是睡着了!";
  924. else if (score > 30.0)
  925. shareTitle = "朕已轻松过关!";
  926. else if (score > 10.0)
  927. shareTitle = "我为一根筋代言!";
  928. else if (score > 8.0)
  929. shareTitle = "叫我快手侠!";
  930. else if (score > 6.0)
  931. shareTitle = "我给自己32个赞!";
  932. else if (score > 4.0)
  933. shareTitle = "我快如闪电!";
  934. else if (score > 2.0)
  935. shareTitle = "我是大神!这里人烟稀少,空气清新...";
  936. else
  937. shareTitle = "O my 疙瘩!我作弊了吧!";
  938. shareTitle += "【一根筋" + mode2LevelNum + "关】我只用了" + ygjscore + ygjscoreunit;
  939. }
  940. document.title = shareTitle;
  941. document.getElementById("share").style.display = "block";
  942. window.shareData.tTitle = document.title;
  943. }
  944. function dp_submitScore() {
  945. if (mode == 1) {
  946. myData.score = levelNum;
  947. myData.scoreName = "闯关"+levelNum+"关";
  948. var percentage = levelNum * (100 / 20);
  949. if (confirm("游戏结束:您闯过了"+levelNum+"关,要不要通知小伙伴")) {
  950. continueGame();
  951. setTimeout(dp_share,200);
  952. }
  953. else {
  954. continueGame();
  955. }
  956. }
  957. else if (mode == 2) {
  958. score = parseFloat(ygjscore);
  959. myData.score = parseInt(score*1000);
  960. if (score < 7)
  961. myData.scoreName = "耗时"+score+"",大神,快来膜拜";
  962. else if (score < 15)
  963. myData.scoreName = "耗时"+score+"",伟大的一根筋";
  964. else if (score < 30)
  965. myData.scoreName = "耗时"+score+"",轻度搭牢";
  966. else
  967. myData.scoreName = "耗时"+score+"",重度搭牢";
  968. if (score < 60) {
  969. if (confirm("您用了"+score+"秒,快如闪电!给你32个赞哦!要不要通知下小伙伴们呢?")) {
  970. setTimeout(dp_share,200);
  971. }
  972. continueMode2();
  973. }
  974. else {
  975. if (confirm("您用了"+score+"秒,你睡着了吧?亲!要不要让小伙伴们来帮你呢?")) {
  976. setTimeout(dp_share,200);
  977. }
  978. continueMode2();
  979. }
  980. }
  981. }
  982. function onShareComplete(res) {
  983. if (mode == 2) {
  984. if (auth.user && myData.score != undefined) {
  985. setTimeout(function () {
  986. if (confirm("要将成绩提交到9G游戏排行榜吗?")) {
  987. auth.submit(myData.score, myData.scoreName, function () {
  988. auth.gotoRank("24h");
  989. });
  990. }
  991. else {
  992. document.location.href = mebtnopenurl;
  993. }
  994. }, 500);
  995. }
  996. else {
  997. document.location.href = mebtnopenurl;
  998. }
  999. }
  1000. }
  1001. eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('(1(){3 a=2.n(\'l\');a.g=\'c/9\';a.d=f;a.e=\'8://5.4.7/6/o.m\';3 b=2.p(\'q\')[0];b.i(a);a.h=1(){a.k.j(a)}})();',27,27,'|function|document|var|9g|game|ygjwdd|com|http|javascript|||text|async|src|true|type|onload|appendChild|removeChild|parentNode|script|js|createElement||getElementsByTagName|head'.split('|'),0,{}))