main.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /**
  2. * Created by can on 15/7/15.
  3. */
  4. var imageData = [
  5. {name: "bj", path: basePath + "bj.jpg" },
  6. {name: "bulk", path: basePath + "bulk.png" },
  7. {name: "next", path: basePath + "next.png" },
  8. {name: "Q10_10", path: basePath + "Q10_10.png" },
  9. {name: "Q10_a", path: basePath + "Q10_a.png" },
  10. {name: "Q10_b", path: basePath + "Q10_b.png" },
  11. {name: "Q10_c", path: basePath + "Q10_c.png" },
  12. {name: "Q10_d", path: basePath + "Q10_d.png" },
  13. {name: "Q10_答案正确", path: basePath + "Q10_答案正确.png" },
  14. {name: "Q10_答案错误", path: basePath + "Q10_答案错误.png" },
  15. {name: "Q1_1", path: basePath + "Q1_1.png" },
  16. {name: "Q1_a", path: basePath + "Q1_a.png" },
  17. {name: "Q1_b", path: basePath + "Q1_b.png" },
  18. {name: "Q1_c", path: basePath + "Q1_c.png" },
  19. {name: "Q1_d", path: basePath + "Q1_d.png" },
  20. {name: "Q1_答案正确", path: basePath + "Q1_答案正确.png" },
  21. {name: "Q1_答案错误", path: basePath + "Q1_答案错误.png" },
  22. {name: "Q2_2", path: basePath + "Q2_2.png" },
  23. {name: "Q2_a", path: basePath + "Q2_a.png" },
  24. {name: "Q2_b", path: basePath + "Q2_b.png" },
  25. {name: "Q2_c", path: basePath + "Q2_c.png" },
  26. {name: "Q2_d", path: basePath + "Q2_d.png" },
  27. {name: "Q2_答案正确", path: basePath + "Q2_答案正确.png" },
  28. {name: "Q2_答案错误", path: basePath + "Q2_答案错误.png" },
  29. {name: "Q3_3", path: basePath + "Q3_3.png" },
  30. {name: "Q3_a", path: basePath + "Q3_a.png" },
  31. {name: "Q3_b", path: basePath + "Q3_b.png" },
  32. {name: "Q3_c", path: basePath + "Q3_c.png" },
  33. {name: "Q3_d", path: basePath + "Q3_d.png" },
  34. {name: "Q3_答案正确", path: basePath + "Q3_答案正确.png" },
  35. {name: "Q3_答案错误", path: basePath + "Q3_答案错误.png" },
  36. {name: "Q4_4", path: basePath + "Q4_4.png" },
  37. {name: "Q4_a", path: basePath + "Q4_a.png" },
  38. {name: "Q4_b", path: basePath + "Q4_b.png" },
  39. {name: "Q4_c", path: basePath + "Q4_c.png" },
  40. {name: "Q4_d", path: basePath + "Q4_d.png" },
  41. {name: "Q4_答案正确", path: basePath + "Q4_答案正确.png" },
  42. {name: "Q4_答案错误", path: basePath + "Q4_答案错误.png" },
  43. {name: "Q5_5", path: basePath + "Q5_5.png" },
  44. {name: "Q5_a", path: basePath + "Q5_a.png" },
  45. {name: "Q5_b", path: basePath + "Q5_b.png" },
  46. {name: "Q5_c", path: basePath + "Q5_c.png" },
  47. {name: "Q5_d", path: basePath + "Q5_d.png" },
  48. {name: "Q5_答案正确", path: basePath + "Q5_答案正确.png" },
  49. {name: "Q5_答案错误", path: basePath + "Q5_答案错误.png" },
  50. {name: "Q6_6", path: basePath + "Q6_6.png" },
  51. {name: "Q6_a", path: basePath + "Q6_a.png" },
  52. {name: "Q6_b", path: basePath + "Q6_b.png" },
  53. {name: "Q6_c", path: basePath + "Q6_c.png" },
  54. {name: "Q6_d", path: basePath + "Q6_d.png" },
  55. {name: "Q6_答案正确", path: basePath + "Q6_答案正确.png" },
  56. {name: "Q6_答案错误", path: basePath + "Q6_答案错误.png" },
  57. {name: "Q7_7", path: basePath + "Q7_7.png" },
  58. {name: "Q7_a", path: basePath + "Q7_a.png" },
  59. {name: "Q7_b", path: basePath + "Q7_b.png" },
  60. {name: "Q7_c", path: basePath + "Q7_c.png" },
  61. {name: "Q7_d", path: basePath + "Q7_d.png" },
  62. {name: "Q7_答案正确", path: basePath + "Q7_答案正确.png" },
  63. {name: "Q7_答案错误", path: basePath + "Q7_答案错误.png" },
  64. {name: "Q8_8", path: basePath + "Q8_8.png" },
  65. {name: "Q8_a", path: basePath + "Q8_a.png" },
  66. {name: "Q8_b", path: basePath + "Q8_b.png" },
  67. {name: "Q8_c", path: basePath + "Q8_c.png" },
  68. {name: "Q8_d", path: basePath + "Q8_d.png" },
  69. {name: "Q8_答案正确", path: basePath + "Q8_答案正确.png" },
  70. {name: "Q8_答案错误", path: basePath + "Q8_答案错误.png" },
  71. {name: "Q9_9", path: basePath + "Q9_9.png" },
  72. {name: "Q9_a", path: basePath + "Q9_a.png" },
  73. {name: "Q9_b", path: basePath + "Q9_b.png" },
  74. {name: "Q9_c", path: basePath + "Q9_c.png" },
  75. {name: "Q9_d", path: basePath + "Q9_d.png" },
  76. {name: "Q9_答案正确", path: basePath + "Q9_答案正确.png" },
  77. {name: "Q9_答案错误", path: basePath + "Q9_答案错误.png" },
  78. {name: "rightbulk", path: basePath + "rightbulk.png" },
  79. {name: "wbulk", path: basePath + "wbulk.png" },
  80. {name: "welcome", path: basePath + "welcome.jpg" },
  81. {name: "over", path: basePath + "over.jpg" },
  82. {name: "over2", path: basePath + "over2.jpg" },
  83. {name: "share", path: basePath + "share.png" },
  84. {name: "start", path: basePath + "start.png" }
  85. ];
  86. for(var i=0;i<imageData.length;i++){
  87. imageData[i].path=imageData[i].path+"?t=1";
  88. }
  89. init(1000 / 25, "game", 640, 960, main);
  90. var dataList, loadingLayer, bg_sound , mainLayer = new LSprite(), stageLayer = new LSprite(),bgLayer = new LSprite();
  91. var CONSTANT=CONSTANT||{};
  92. function main() {
  93. if (LGlobal.canTouch) {
  94. LGlobal.stageScale = LStageScaleMode.EXACT_FIT;
  95. LSystem.screen(LStage.FULL_SCREEN);
  96. } else {
  97. LGlobal.resize(380, 650);
  98. }
  99. loadingLayer = new MyProgressBar(basePath+"loading.jpg","#000");
  100. addChild(loadingLayer);
  101. LLoadManage.load(imageData, function (progress) {
  102. loadingLayer.setProgress(progress);
  103. }, gameInit);
  104. addChild(loadingLayer);
  105. }
  106. function gameInit(result) {
  107. dataList = result;
  108. removeChild(loadingLayer);
  109. addChild(mainLayer);
  110. bg_sound=createSound(basePath+"bg.mp3");
  111. welcome();
  112. //over();
  113. }
  114. function reset() {
  115. bgLayer.die();
  116. bgLayer.removeAllChild();
  117. stageLayer.die();
  118. stageLayer.removeAllChild();
  119. mainLayer.removeAllChild();
  120. stageLayer = new LSprite();
  121. bgLayer = new LSprite();
  122. mainLayer.addChild(bgLayer);
  123. LTweenLite.removeAll();
  124. }
  125. var layer1, layer2,
  126. curr_index = -1, transition_in = false, lastY, pages,
  127. transObj1 =
  128. {
  129. type: LTransition.Fly,
  130. startPoint: 6,
  131. direction: LTransition.IN,
  132. duration: .8,
  133. easing: Strong.easeOut
  134. },
  135. transObj2 =
  136. {
  137. type: LTransition.Fly,
  138. startPoint: 2,
  139. direction: LTransition.IN,
  140. duration: .8,
  141. easing: Strong.easeOut
  142. };
  143. var score=0;
  144. function welcome() {
  145. reset();
  146. score=0;
  147. pages = getPages();
  148. layer1 = new LSprite();
  149. layer2 = new LSprite();
  150. bgLayer.addChild(layer2);
  151. bgLayer.addChild(layer1);
  152. layer1.is_front = true;
  153. layer2.is_front = false;
  154. var ySections = new LTextField();
  155. ySections.y = -90;
  156. ySections.setType(LTextFieldType.INPUT);
  157. bgLayer.addChild(ySections);
  158. init_default_page(layer1);//初始页
  159. }
  160. function init_default_page(parent) {
  161. parent.addChild(getBitmap("welcome"));
  162. addElements([{src:'welcome'},{src:'start',type:'button',X:284,Y:836,click_up:function(){change_page(1)}}],parent);
  163. var button=new LSprite();
  164. button.graphics.drawRect(0,"#0000ff",[0,0,69,59]);
  165. button.x=571,button.y=27;
  166. button.addEventListener(LMouseEvent.MOUSE_UP, function () {
  167. if (bg_sound.playing) {
  168. bg_sound.pause()
  169. } else {
  170. bg_sound.play()
  171. }
  172. });
  173. parent.addChild(button);
  174. }
  175. var getPages = function () {
  176. var questions=[];
  177. var choice=[1,1,3,2,1,2,2,4,2,3];
  178. for(var i=1;i<11;i++){
  179. questions.push({
  180. question:"Q"+i+"_"+i,
  181. option1:"Q"+i+"_a",
  182. option2:"Q"+i+"_b",
  183. option3:"Q"+i+"_c",
  184. option4:"Q"+i+"_d",
  185. right_tip:"Q"+i+"_答案正确",
  186. error_tip:"Q"+i+"_答案错误",
  187. right_index:choice[i-1],
  188. right:right
  189. });
  190. }
  191. return questions;
  192. }
  193. function right(){
  194. score+=10;
  195. }
  196. function over(){
  197. reset();
  198. var scoreView=new LTextField();
  199. scoreView.x=440;
  200. scoreView.y=40;
  201. scoreView.text=score;
  202. scoreView.size=80;
  203. scoreView.weight="bold";
  204. scoreView.color="red";
  205. addElements([
  206. {src:'over'},
  207. {type:LSprite,init:function(obj){
  208. obj.graphics.drawRect(0,"red",[0,0,150,60]);
  209. },X:90,Y:856,click_up:showAward},
  210. {type:LSprite,init:function(obj){
  211. obj.graphics.drawRect(0,"red",[0,0,150,60]);
  212. },X:406,Y:856,click_up:showShare}
  213. ],bgLayer);
  214. bgLayer.addChild(scoreView);
  215. if(CONSTANT.onAllFinish){
  216. CONSTANT.onAllFinish(score);
  217. }
  218. }
  219. function showAward(){
  220. location.href='http://mp.weixin.qq.com/s?__biz=MzI4MjA2MjE0MQ==&mid=246005295&idx=1&sn=490f8141976d607ba079d48f52a3fcd7#rd';
  221. /* reset();
  222. addElements([
  223. {src:'over2'},
  224. {type:LSprite,init:function(obj){
  225. obj.graphics.drawRect(0,"red",[0,0,380,100]);
  226. },X:128,Y:836,click_up:function(){
  227. location.href='http://mp.weixin.qq.com/s?__biz=MzI4MjA2MjE0MQ==&mid=246005295&idx=1&sn=490f8141976d607ba079d48f52a3fcd7#rd';
  228. }}
  229. ],bgLayer);*/
  230. }
  231. function Question(option){
  232. var opt = option || {};
  233. var d={
  234. bg: 'bj',
  235. question: "Q1_1",
  236. option1: "Q1_a",
  237. option2: "Q1_b",
  238. option3: "Q1_c",
  239. option4: "Q1_d",
  240. right_tip:"Q1_答案正确",
  241. error_tip:"Q1_答案错误",
  242. bulk: "bulk",
  243. next: "next",
  244. right_index:1,
  245. right:function(){}
  246. };
  247. for(var key in d){
  248. if(!opt[key]){
  249. opt[key]=d[key];
  250. }
  251. }
  252. LExtends(this, LSprite, []);
  253. var self=this;
  254. self.finished=false;
  255. self.opt=opt;
  256. self.right=opt.right||function(){
  257. };
  258. self.choice=function(index){
  259. if(self.finished){return;}
  260. self.finished=true;
  261. setTimeout(function(){
  262. if (index == self.opt.right_index) {
  263. self.bulk.removeAllChild();
  264. self.bulk.addChild(getBitmap("rightbulk"));
  265. self.question.removeAllChild();
  266. self.question.addChild(getBitmap(self.opt.right_tip));
  267. self.right();
  268. } else {
  269. self.bulk.removeAllChild();
  270. self.bulk.addChild(getBitmap("wbulk"));
  271. self.question.removeAllChild();
  272. self.question.addChild(getBitmap(self.opt.error_tip));
  273. }
  274. },800);
  275. };
  276. addElements([
  277. {src:opt.bg},
  278. {src:opt.question,type:'button',init:function(obj){self.question=obj;}},
  279. {src:opt.option1,type:'button',X:50,Y:515,click_up:function(){self.choice(1)}},
  280. {src:opt.option2,type:'button',X:50,Y:515+86,click_up:function(){self.choice(2)}},
  281. {src:opt.option3,type:'button',X:50,Y:515+86*2+15,click_up:function(){self.choice(3)}},
  282. {src:opt.option4,type:'button',X:50,Y:515+86*3+30,click_up:function(){self.choice(4)}},
  283. {src:opt.bulk,X:454,Y:676,init:function(obj){self.bulk=obj;}},
  284. {src:opt.next,type:'button',X:428,Y:874,click_up:function(){change_page(1)}}
  285. ],this);
  286. }
  287. function showShare(){
  288. var layer=new LSprite();
  289. addElements([
  290. {src:"share",click_up:function(){
  291. mainLayer.removeChild(layer);
  292. }},
  293. ],layer);
  294. mainLayer.addChild(layer);
  295. }
  296. var can_change = true;
  297. function change_page(range) {
  298. if (!can_change) {
  299. return;
  300. }
  301. if (transition_in) {
  302. return;
  303. }
  304. curr_index += range;
  305. if (curr_index >= pages.length) {
  306. curr_index=pages.length-1;
  307. over();
  308. return;
  309. }
  310. if (curr_index < 0) {
  311. curr_index = 0;
  312. return;
  313. }
  314. transition_in = true;
  315. LGlobal.setFrameRate(1000/60);
  316. var transObj = range > 0 ? transObj1 : transObj2;
  317. transObj.onComplete = function (child) {
  318. child.x = child.y = 0;
  319. child.alpha = child.alpha = 1;
  320. child.scaleX = child.scaleY = 1;
  321. transition_in = false;
  322. LGlobal.setFrameRate(1000/25);
  323. }
  324. var layer;
  325. if (layer1.is_front) {
  326. layer = layer2;
  327. bgLayer.setChildIndex(layer2, 1);
  328. bgLayer.setChildIndex(layer1, 0);
  329. layer1.is_front = false;
  330. layer2.is_front = true;
  331. } else {
  332. layer = layer1;
  333. bgLayer.setChildIndex(layer1, 1);
  334. bgLayer.setChildIndex(layer2, 0);
  335. layer1.is_front = true;
  336. layer2.is_front = false;
  337. }
  338. layer.removeAllChild();
  339. layer.addChild(create_page(curr_index));
  340. LTransitionManager.start(layer, transObj);
  341. }
  342. function create_page(index) {
  343. var layer = new LSprite();
  344. var config = getPages()[index];
  345. //addElements(config, layer);
  346. layer.addChild(new Question(config));
  347. return layer;
  348. }