PetManager.js 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636
  1. /**
  2. * @author liaomengcheng
  3. */
  4. FZ.GRID_COOR = FZ.newClass({
  5. line: 0,
  6. col: 0,
  7. init: function(){
  8. this.line = 0;
  9. this.col = 0;
  10. }
  11. });
  12. FZ.DiamondManager = FZ.newClass({
  13. EVT_MOUSE_OVER: "mouseover",
  14. EVT_MOUSE_MOVE: "mousemove",
  15. EVT_MOUSE_OUT: "mouseout",
  16. EVT_MOUSE_CLICK: "click",
  17. m_hintX: 0,
  18. m_hintY: 0,
  19. m_hintScore: null,
  20. m_last_selected: -1,
  21. // m_spr: null,
  22. m_dialog: false,
  23. m_leftNum: -1,
  24. m_allPets: null,
  25. m_missDiamonds: null,
  26. // m_worldMatrix: null,
  27. m_hintCount: 0,
  28. m_bonus_time: 0,
  29. m_firstPet: null,
  30. m_secondPet: null,
  31. m_PetFirstIndex: 0,
  32. m_PetSecondIndex: 0,
  33. m_drawLineTime: 0,
  34. m_left_pet: 0,
  35. m_ctx: null,
  36. m_level: 0,
  37. m_displayPetsIndex: null,
  38. m_reset_finished: true,
  39. m_parent: null,
  40. m_observer: null,
  41. m_stop_bubble: false,
  42. m_call_mOver: null,
  43. m_call_mOut: null,
  44. m_call_mMove: null,
  45. m_call_mClick: null,
  46. m_call_tStart: null,
  47. m_call_tMove: null,
  48. m_call_tEnd: null,
  49. m_div_line: [],
  50. isDebug: false,
  51. m_debug_div: null,
  52. init: function(){
  53. this.m_hintX = 0;
  54. this.m_hintY = 0;
  55. this.m_hintScore = "";
  56. this.m_last_selected = -1;
  57. // this.m_spr = null;
  58. this.m_dialog = false;
  59. this.m_leftNum = -1;
  60. // this.m_worldMatrix = new FZ.Math.Matrix3();
  61. // this.m_worldMatrix.identity();
  62. this.m_allPets = (this.m_allPets || []);
  63. this.m_missDiamonds = (this.m_missDiamonds || []);
  64. this.m_hintCount = 0;
  65. this.m_firstPet = null;
  66. this.m_secondPet = null;
  67. this.m_PetFirstIndex = 0;
  68. this.m_PetSecondIndex = 0;
  69. this.m_drawLineTime = 0;
  70. this.m_left_pet = FZ.GameDefs.ALL_PET_NUM;
  71. for (var index = 0; index < 3; ++index) {
  72. this.m_div_line[index] = document.createElement("div");
  73. this.m_div_line[index].style.position = "absolute";
  74. this.m_div_line[index].style.backgroundRepeat = "no-repeat";
  75. this.m_div_line[index].style.backgroundColor = "#ffff00";
  76. // this.m_div_line[index].style.display = "none";
  77. this.m_div_line[index].style.visibility = "hidden";
  78. FZ.DivManager.addChild(this.m_div_line[index]);
  79. }
  80. if (this.isDebug) {
  81. this.m_debug_div = document.createElement("div");
  82. this.m_debug_div.style.zIndex = 500;
  83. this.m_debug_div.style.width = 320 + "px";
  84. this.m_debug_div.style.height = 40 + "px";
  85. this.m_debug_div.style.left = 0 + "px";
  86. this.m_debug_div.style.top = 438 + "px";
  87. this.m_debug_div.style.position = "absolute";
  88. this.m_debug_div.style.color = "#ff0";
  89. this.m_debug_div.style.fontSize = FZ.GameDefs.STATS_FONT_SIZE + "px";
  90. this.m_debug_div.style.fontFamily = "Arial";
  91. this.m_debug_div.style.lineHeight = 40 + "px";
  92. this.m_debug_div.style.textAlign = "center";
  93. this.m_debug_div.style.innerHTML = "";
  94. FZ.DivManager.addChild(this.m_debug_div);
  95. }
  96. },
  97. removeEvent: function(){
  98. if (!this.m_parent) {
  99. return;
  100. }
  101. if (FZ.TARGET_DEF.MOBILE === FZ.TargetPort) {
  102. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.T_START, this.m_call_tStart);
  103. this.m_call_tStart = null;
  104. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.T_MOVE, this.m_call_tMove);
  105. this.m_call_tMove = null;
  106. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.T_END, this.m_call_tEnd);
  107. this.m_call_tEnd = null;
  108. }
  109. else {
  110. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.M_OVER, this.m_call_mOver);
  111. this.m_call_mOver = null;
  112. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.M_OUT, this.m_call_mOut);
  113. this.m_call_mOut = null;
  114. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.M_MOVE, this.m_call_mMove);
  115. this.m_call_mMove = null;
  116. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.M_CLICK, this.m_call_mClick);
  117. this.m_call_mClick = null;
  118. }
  119. },
  120. setParent: function(obj){
  121. // var that = this;
  122. if (obj) {
  123. this.m_parent = obj;
  124. if (FZ.TARGET_DEF.MOBILE === FZ.TargetPort) {
  125. FZ.EventHandler(this, this.m_parent, FZ.EVENT_DEF.T_START, this.mouseHandler);
  126. FZ.EventHandler(this, this.m_parent, FZ.EVENT_DEF.T_MOVE, this.mouseHandler);
  127. FZ.EventHandler(this, this.m_parent, FZ.EVENT_DEF.T_END, this.mouseHandler);
  128. // this.m_parent.ontouchstart = this.m_parent.ontouchmove = this.m_parent.ontouchend = function(evt) {
  129. // that.mouseHandler.call(that, evt);
  130. // };
  131. }
  132. else {
  133. FZ.EventHandler(this, this.m_parent, FZ.EVENT_DEF.M_OVER, this.mouseHandler);
  134. FZ.EventHandler(this, this.m_parent, FZ.EVENT_DEF.M_MOVE, this.mouseHandler);
  135. FZ.EventHandler(this, this.m_parent, FZ.EVENT_DEF.M_OUT, this.mouseHandler);
  136. FZ.EventHandler(this, this.m_parent, FZ.EVENT_DEF.M_CLICK, this.mouseHandler);
  137. // this.m_parent.onclick = this.m_parent.onmousemove = this.m_parent.onmouseout = this.m_parent.onmouseover = function(evt){
  138. // that.mouseHandler.call(that, evt);
  139. // };
  140. }
  141. }
  142. else
  143. if (this.m_parent) {
  144. if (FZ.TARGET_DEF.MOBILE === FZ.TargetPort) {
  145. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.T_START, this.m_call_tStart);
  146. this.m_call_tStart = null;
  147. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.T_MOVE, this.m_call_tMove);
  148. this.m_call_tMove = null;
  149. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.T_END, this.m_call_tEnd);
  150. this.m_call_tEnd = null;
  151. // this.m_parent.ontouchstart = null;
  152. // this.m_parent.ontouchmove = null;
  153. // this.m_parent.ontouchend = null;
  154. }
  155. else {
  156. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.M_OVER, this.m_call_mOver);
  157. this.m_call_mOver = null;
  158. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.M_OUT, this.m_call_mOut);
  159. this.m_call_mOut = null;
  160. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.M_MOVE, this.m_call_mMove);
  161. this.m_call_mMove = null;
  162. FZ.EventRemove(this, this.m_parent, FZ.EVENT_DEF.M_CLICK, this.m_call_mClick);
  163. this.m_call_mClick = null;
  164. // this.m_parent.onmouseover = null;
  165. // this.m_parent.onmouseout = null;
  166. // this.m_parent.onmousemove = null;
  167. // this.m_parent.onclick = null;
  168. }
  169. //// this.m_parent = obj;
  170. // if(FZ.TARGET_DEF.MOBILE === FZ.TargetPort) {
  171. // this.m_parent.ontouchstart = null;
  172. // this.m_parent.ontouchmove = null;
  173. // this.m_parent.ontouchend = null;
  174. // }
  175. // else {
  176. // this.m_parent.onmouseover = null;
  177. // this.m_parent.onmouseout = null;
  178. // this.m_parent.onmousemove = null;
  179. // this.m_parent.onmouseclick = null;
  180. // }
  181. }
  182. // this.createLabels();
  183. },
  184. setBubble: function(value){
  185. this.m_stop_bubble = value;
  186. },
  187. setObserver: function(obj){
  188. this.m_observer = obj;
  189. },
  190. setCtx: function(ctx){
  191. this.m_ctx = ctx;
  192. },
  193. setASprite: function(spr){
  194. this.m_spr = spr;
  195. },
  196. clearAllPets: function(){
  197. var pet = null;
  198. while (this.m_allPets.length > 0) {
  199. pet = this.m_allPets.pop();
  200. if (pet) {
  201. pet.destroy();
  202. }
  203. }
  204. },
  205. getTouchPetIndex: function(posX, posY){
  206. var index = 0;
  207. if ((posX < FZ.GameDefs.DREAMPET_OFFSET_X) ||
  208. (posX > (FZ.GameDefs.DREAMPET_OFFSET_X + (FZ.GameDefs.DREAMPET_NUM_COL + 1) * FZ.GameDefs.GRID_WIDTH)) ||
  209. (posY < FZ.GameDefs.DREAMPET_OFFSET_Y) ||
  210. (posY > (FZ.GameDefs.DREAMPET_OFFSET_Y + (FZ.GameDefs.DREAMPET_NUM_LINE + 1) * FZ.GameDefs.GRID_HEIGHT))) {
  211. return -1;
  212. }
  213. var col = (posY - FZ.GameDefs.DREAMPET_OFFSET_Y) / FZ.GameDefs.GRID_HEIGHT;
  214. var line = (posX - FZ.GameDefs.DREAMPET_OFFSET_X) / FZ.GameDefs.GRID_WIDTH;
  215. index = col * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + line;
  216. if (index >= ((FZ.GameDefs.DREAMPET_NUM_LINE + 2) * (FZ.GameDefs.DREAMPET_NUM_COL + 2))) {
  217. index = -1;
  218. }
  219. return index;
  220. },
  221. checkFocus: function(){
  222. var index = 0;
  223. for (index = 0; index < (FZ.GameDefs.ALL_GENERAL); index++) {
  224. var state = this.m_allPets[index].getState();
  225. if (state === FZ.GameDefs.DREAMPET_FOCUS) {
  226. //alert(index);
  227. return true;
  228. }
  229. }
  230. return false;
  231. },
  232. searchHint: function(){
  233. var p1 = new FZ.GRID_COOR();
  234. var p2 = new FZ.GRID_COOR();
  235. var randomId = Math.floor(FZ.Math.random(0, FZ.GameDefs.ALL_GENERAL - 1));
  236. for (var PetFirstIndex = randomId; PetFirstIndex < FZ.GameDefs.ALL_GENERAL; PetFirstIndex++) {
  237. if (this.m_allPets[PetFirstIndex].getState() === FZ.GameDefs.DREAMPET_REMOVE)
  238. continue;
  239. p1.col = this.m_allPets[PetFirstIndex].getCol();
  240. p1.line = this.m_allPets[PetFirstIndex].getLine();
  241. for (var PetSecondIndex = PetFirstIndex + 1; PetSecondIndex < FZ.GameDefs.ALL_GENERAL; PetSecondIndex++) {
  242. if (this.m_allPets[PetSecondIndex].getState() === FZ.GameDefs.DREAMPET_REMOVE)
  243. continue;
  244. if (this.m_allPets[PetFirstIndex].getStyle() !== this.m_allPets[PetSecondIndex].getStyle())
  245. continue;
  246. p2.col = this.m_allPets[PetSecondIndex].getCol();
  247. p2.line = this.m_allPets[PetSecondIndex].getLine();
  248. if ((FZ.AG.SearchSpecialPath.getPath(this.m_allPets, (FZ.GameDefs.DREAMPET_NUM_LINE + 2), (FZ.GameDefs.DREAMPET_NUM_COL + 2), p1.col, p1.line, p2.col, p2.line)) !== null) {
  249. this.m_allPets[PetFirstIndex].setState(FZ.GameDefs.DREAMPET_FLASH_HINT);
  250. this.m_allPets[PetFirstIndex].setPetFocus();
  251. this.m_allPets[PetSecondIndex].setState(FZ.GameDefs.DREAMPET_FLASH_HINT);
  252. this.m_allPets[PetSecondIndex].setPetFocus();
  253. // this.m_PetFirstIndex = PetFirstIndex;
  254. // this.m_PetSecondIndex = PetSecondIndex;
  255. //this.m_hasHint = true;
  256. this.m_hintCount--;
  257. return true;
  258. }
  259. }
  260. }
  261. for (var PetFirstIndex = 0; PetFirstIndex < randomId; PetFirstIndex++) {
  262. if (this.m_allPets[PetFirstIndex].getState() === FZ.GameDefs.DREAMPET_REMOVE)
  263. continue;
  264. p1.col = this.m_allPets[PetFirstIndex].getCol();
  265. p1.line = this.m_allPets[PetFirstIndex].getLine();
  266. for (var PetSecondIndex = PetFirstIndex + 1; PetSecondIndex < FZ.GameDefs.ALL_GENERAL; PetSecondIndex++) {
  267. if (this.m_allPets[PetSecondIndex].getState() === FZ.GameDefs.DREAMPET_REMOVE)
  268. continue;
  269. if (this.m_allPets[PetFirstIndex].getStyle() !== this.m_allPets[PetSecondIndex].getStyle())
  270. continue;
  271. p2.col = this.m_allPets[PetSecondIndex].getCol();
  272. p2.line = this.m_allPets[PetSecondIndex].getLine();
  273. if ((FZ.AG.SearchSpecialPath.getPath(this.m_allPets, (FZ.GameDefs.DREAMPET_NUM_LINE + 2), (FZ.GameDefs.DREAMPET_NUM_COL + 2), p1.col, p1.line, p2.col, p2.line)) !== null) {
  274. this.m_allPets[PetFirstIndex].setState(FZ.GameDefs.DREAMPET_FLASH_HINT);
  275. this.m_allPets[PetFirstIndex].setPetFocus();
  276. this.m_allPets[PetSecondIndex].setState(FZ.GameDefs.DREAMPET_FLASH_HINT);
  277. this.m_allPets[PetSecondIndex].setPetFocus();
  278. // this.m_PetFirstIndex = PetFirstIndex;
  279. // this.m_PetSecondIndex = PetSecondIndex;
  280. this.m_hintCount--;
  281. // this.m_hasHint = true;
  282. return true;
  283. }
  284. }
  285. }
  286. return false;
  287. },
  288. searchHasMatch: function(){
  289. var p1 = new FZ.GRID_COOR();
  290. var p2 = new FZ.GRID_COOR();
  291. // var randomId = Math.floor(FZ.Math.random(0, FZ.GameDefs.ALL_GENERAL - 1));
  292. var tmp = this.m_PointPath;
  293. for (var PetFirstIndex = 0; PetFirstIndex < FZ.GameDefs.ALL_GENERAL; PetFirstIndex++) {
  294. if (this.m_allPets[PetFirstIndex].getState() === FZ.GameDefs.DREAMPET_REMOVE)
  295. continue;
  296. p1.col = this.m_allPets[PetFirstIndex].getCol();
  297. if (p1.col < 0) {
  298. continue;
  299. }
  300. p1.line = this.m_allPets[PetFirstIndex].getLine();
  301. if (p1.line < 0) {
  302. continue;
  303. }
  304. for (var PetSecondIndex = PetFirstIndex + 1; PetSecondIndex < FZ.GameDefs.ALL_GENERAL; PetSecondIndex++) {
  305. if (this.m_allPets[PetSecondIndex].getState() === FZ.GameDefs.DREAMPET_REMOVE)
  306. continue;
  307. if (this.m_allPets[PetFirstIndex].getStyle() !== this.m_allPets[PetSecondIndex].getStyle())
  308. continue;
  309. p2.col = this.m_allPets[PetSecondIndex].getCol();
  310. if (p2.col < 0) {
  311. continue;
  312. }
  313. p2.line = this.m_allPets[PetSecondIndex].getLine();
  314. if (p2.line < 0) {
  315. continue;
  316. }
  317. if (FZ.AG.SearchSpecialPath.getPath(this.m_allPets, (FZ.GameDefs.DREAMPET_NUM_LINE + 2), (FZ.GameDefs.DREAMPET_NUM_COL + 2), p1.col, p1.line, p2.col, p2.line) !== null) {
  318. this.m_PointPath = tmp;
  319. return true;
  320. }
  321. }
  322. }
  323. if (this.isDebug) {
  324. this.m_debug_div.style.backgroundColor = "#000";
  325. }
  326. this.m_PointPath = tmp;
  327. return false;
  328. },
  329. ResetPosition: function(){
  330. var firstId;
  331. var secondId;
  332. var petIndex = null;
  333. this.getDisplayPet();
  334. petIndex = this.m_displayPetsIndex;
  335. var len = petIndex.length;
  336. var randId = 0;
  337. if (len === 4) {
  338. this.exchagePet(petIndex[0], petIndex[1]);
  339. return;
  340. }
  341. randId = Math.floor(FZ.Math.random(1, len - 2));
  342. for (var index = 0; index < randId - 1; index++) {
  343. firstId = petIndex[index];
  344. secondId = petIndex[index + 1];
  345. this.exchagePet(firstId, secondId);
  346. }
  347. for (var index = randId; index < len - 2; index++) {
  348. firstId = petIndex[index];
  349. secondId = petIndex[index + 1];
  350. this.exchagePet(firstId, secondId);
  351. }
  352. },
  353. ResetTwoPosition: function(){
  354. var firstId;
  355. var secondId;
  356. var petIndex = null;
  357. this.getDisplayPet();
  358. petIndex = this.m_displayPetsIndex;
  359. var len = petIndex.length;
  360. firstId = petIndex[0];
  361. for (var index = 1; index < len - 1; index++) {
  362. secondId = petIndex[index];
  363. if (this.m_allPets[firstId].getStyle() !== this.m_allPets[secondId].getStyle()) {
  364. continue;
  365. }
  366. else {
  367. this.exchagePet(petIndex[1], secondId);
  368. break;
  369. }
  370. }
  371. },
  372. resetPetPosEffect: function(){
  373. if (this.m_PetFirstIndex > 0) {
  374. var curLevel = FZ.GameBase.SaveObject.m_cur_level;
  375. switch (curLevel) {
  376. case 1:{
  377. // this.centerReset(this.m_PetFirstIndex, this.m_PetSecondIndex);
  378. break;
  379. }
  380. case 2:{
  381. break;
  382. }
  383. case 3:{
  384. this.updownReset(this.m_PetFirstIndex, this.m_PetSecondIndex);
  385. break;
  386. }
  387. case 4:{
  388. break;
  389. }
  390. case 5:{
  391. this.leftrightReset(this.m_PetFirstIndex, this.m_PetSecondIndex);
  392. break;
  393. }
  394. case 6:{
  395. //
  396. break;
  397. }
  398. case 7:{
  399. this.downReset(this.m_PetFirstIndex, this.m_PetSecondIndex);
  400. break;
  401. }
  402. case 8:{
  403. this.rightReset(this.m_PetFirstIndex, this.m_PetSecondIndex);
  404. break;
  405. }
  406. case 9:{
  407. this.leftReset(this.m_PetFirstIndex, this.m_PetSecondIndex);
  408. break;
  409. }
  410. case 10:{
  411. this.upReset(this.m_PetFirstIndex, this.m_PetSecondIndex);
  412. break;
  413. }
  414. default:
  415. break;
  416. }
  417. this.m_PetFirstIndex = 0;
  418. // this.m_left_pet = this.getDisplayPet();
  419. }
  420. },
  421. getDisplayPet: function(){
  422. var displayNum = 0;
  423. this.m_displayPetsIndex = [];
  424. for (var index = 0; index < FZ.GameDefs.ALL_GENERAL; index++) {
  425. var state = this.m_allPets[index].getState();
  426. if (state !== FZ.GameDefs.DREAMPET_REMOVE) {
  427. displayNum++;
  428. this.m_displayPetsIndex.push(index);
  429. }
  430. }
  431. return displayNum;
  432. },
  433. isGreat: function(x, y){
  434. if (x >= y) {
  435. return true;
  436. }
  437. else {
  438. return false;
  439. }
  440. },
  441. setPetDisappear: function(x, y){
  442. //
  443. var pet_index = 0;
  444. var path = [];
  445. if ((x < FZ.GameDefs.DREAMPET_OFFSET_X) ||
  446. (x > (FZ.GameDefs.DREAMPET_OFFSET_X + (FZ.GameDefs.DREAMPET_NUM_COL + 1) * FZ.GameDefs.GRID_WIDTH)) ||
  447. (y < FZ.GameDefs.DREAMPET_OFFSET_Y) ||
  448. (y > (FZ.GameDefs.DREAMPET_OFFSET_Y + (FZ.GameDefs.DREAMPET_NUM_LINE + 1) * FZ.GameDefs.GRID_HEIGHT))) {
  449. return false;
  450. }
  451. var line = Math.floor((y - FZ.GameDefs.DREAMPET_OFFSET_Y) / FZ.GameDefs.GRID_HEIGHT);
  452. var col = Math.floor((x - FZ.GameDefs.DREAMPET_OFFSET_X) / FZ.GameDefs.GRID_WIDTH);
  453. pet_index = line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + col;
  454. if (pet_index >= ((FZ.GameDefs.DREAMPET_NUM_LINE + 2) * (FZ.GameDefs.DREAMPET_NUM_COL + 2))) {
  455. pet_index = -1;
  456. }
  457. //alert("col: " + col +"; line" + line);
  458. //
  459. //index = getTouchPetIndex(x, y);
  460. if (pet_index < 0) {
  461. return false;
  462. }
  463. var tmp = this.m_allPets[pet_index];
  464. if (null === tmp || undefined === tmp) {
  465. return false;
  466. }
  467. if (tmp.getState() === FZ.GameDefs.DREAMPET_FOCUS || tmp.getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  468. return false;
  469. }
  470. else
  471. if (false === this.checkFocus()) {
  472. this.m_allPets[pet_index].setState(FZ.GameDefs.DREAMPET_FOCUS);
  473. this.m_allPets[pet_index].show();
  474. this.m_firstPet = this.m_allPets[pet_index];
  475. return false;
  476. }//start check two Pets can be disappeared
  477. else
  478. // if (true) {
  479. this.m_secondPet = tmp;
  480. p1 = new FZ.GRID_COOR();
  481. p1.line = this.m_firstPet.getLine();
  482. p1.col = this.m_firstPet.getCol();
  483. p2 = new FZ.GRID_COOR();
  484. p2.line = this.m_secondPet.getLine();
  485. p2.col = this.m_secondPet.getCol();
  486. if (this.m_firstPet.getStyle() !== this.m_secondPet.getStyle()) {
  487. this.m_allPets[pet_index].setState(FZ.GameDefs.DREAMPET_FOCUS);
  488. this.m_allPets[pet_index].show();
  489. this.m_firstPet.setState(FZ.GameDefs.DREAMPET_INIT);
  490. this.m_firstPet.hidden();
  491. this.m_firstPet = this.m_secondPet;
  492. return false;
  493. }
  494. //below for 4 kinds steps to check
  495. else
  496. if ((path = FZ.AG.SearchSpecialPath.getPath(this.m_allPets, (FZ.GameDefs.DREAMPET_NUM_LINE + 2), (FZ.GameDefs.DREAMPET_NUM_COL + 2), p1.col, p1.line, p2.col, p2.line)) !== null) {
  497. this.m_PointPath = path;
  498. this.m_allPets[(FZ.GameDefs.DREAMPET_NUM_COL + 2) * p1.line + p1.col].setState(FZ.GameDefs.DREAMPET_FLASH);
  499. this.m_allPets[(FZ.GameDefs.DREAMPET_NUM_COL + 2) * p2.line + p2.col].setState(FZ.GameDefs.DREAMPET_FLASH);
  500. this.m_PetFirstIndex = (FZ.GameDefs.DREAMPET_NUM_COL + 2) * p1.line + p1.col;
  501. this.m_allPets[this.m_PetFirstIndex].hidden();
  502. this.m_PetSecondIndex = (FZ.GameDefs.DREAMPET_NUM_COL + 2) * p2.line + p2.col;
  503. this.m_allPets[this.m_PetFirstIndex].setPetFocus();
  504. this.m_allPets[this.m_PetSecondIndex].setPetFocus();
  505. this.m_score += 100;
  506. this.m_bonus_time += 5;
  507. var lineNum = this.m_PointPath.length;
  508. var temp = [];
  509. for (var index = 0; index < lineNum - 1; ++index) {
  510. temp[1] = this.m_PointPath[index + 1][1];
  511. temp[0] = this.m_PointPath[index + 1][0];
  512. var resultW;
  513. var resultH;
  514. var w = this.ABS((FZ.GameDefs.DREAMPET_OFFSET_X + FZ.GameDefs.GRID_WIDTH * temp[0] + FZ.GameDefs.GRID_WIDTH_HALF), (FZ.GameDefs.DREAMPET_OFFSET_X + FZ.GameDefs.GRID_WIDTH * this.m_PointPath[index][0] + FZ.GameDefs.GRID_WIDTH_HALF));
  515. var h = this.ABS((FZ.GameDefs.DREAMPET_OFFSET_Y + FZ.GameDefs.GRID_HEIGHT * temp[1] + FZ.GameDefs.GRID_HEIGHT_HALF), (FZ.GameDefs.DREAMPET_OFFSET_Y + FZ.GameDefs.GRID_HEIGHT * this.m_PointPath[index][1] + FZ.GameDefs.GRID_HEIGHT_HALF));
  516. var left;
  517. var top;
  518. if (0 === Math.floor(w)) {
  519. w = 3;
  520. }
  521. if (0 === Math.floor(h)) {
  522. h = 3;
  523. }
  524. if (w === 3) {
  525. resultW = this.isGreat((FZ.GameDefs.DREAMPET_OFFSET_Y + FZ.GameDefs.GRID_HEIGHT * temp[1] + FZ.GameDefs.GRID_HEIGHT_HALF), (FZ.GameDefs.DREAMPET_OFFSET_Y + FZ.GameDefs.GRID_HEIGHT * this.m_PointPath[index][1] + FZ.GameDefs.GRID_HEIGHT_HALF));
  526. if (resultW) {
  527. left = FZ.GameDefs.DREAMPET_OFFSET_X + FZ.GameDefs.GRID_WIDTH * this.m_PointPath[index][0] + FZ.GameDefs.GRID_WIDTH_HALF;
  528. top = FZ.GameDefs.DREAMPET_OFFSET_Y + FZ.GameDefs.GRID_HEIGHT * this.m_PointPath[index][1] + FZ.GameDefs.GRID_HEIGHT_HALF;
  529. }
  530. else {
  531. left = FZ.GameDefs.DREAMPET_OFFSET_X + FZ.GameDefs.GRID_WIDTH * this.m_PointPath[index][0] + FZ.GameDefs.GRID_WIDTH_HALF;
  532. top = FZ.GameDefs.DREAMPET_OFFSET_Y + FZ.GameDefs.GRID_HEIGHT * temp[1] + FZ.GameDefs.GRID_HEIGHT_HALF;
  533. h += 3;
  534. }
  535. }
  536. if (h === 3) {
  537. resultH = this.isGreat((FZ.GameDefs.DREAMPET_OFFSET_X + FZ.GameDefs.GRID_WIDTH * temp[0] + FZ.GameDefs.GRID_WIDTH_HALF), (FZ.GameDefs.DREAMPET_OFFSET_X + FZ.GameDefs.GRID_WIDTH * this.m_PointPath[index][0] + FZ.GameDefs.GRID_WIDTH_HALF));
  538. if (resultH) {
  539. left = FZ.GameDefs.DREAMPET_OFFSET_X + FZ.GameDefs.GRID_WIDTH * this.m_PointPath[index][0] + FZ.GameDefs.GRID_WIDTH_HALF;
  540. top = FZ.GameDefs.DREAMPET_OFFSET_Y + FZ.GameDefs.GRID_HEIGHT * this.m_PointPath[index][1] + FZ.GameDefs.GRID_HEIGHT_HALF;
  541. }
  542. else {
  543. left = FZ.GameDefs.DREAMPET_OFFSET_X + FZ.GameDefs.GRID_WIDTH * temp[0] + FZ.GameDefs.GRID_WIDTH_HALF;
  544. top = FZ.GameDefs.DREAMPET_OFFSET_Y + FZ.GameDefs.GRID_HEIGHT * this.m_PointPath[index][1] + FZ.GameDefs.GRID_HEIGHT_HALF;
  545. w += 3;
  546. }
  547. }
  548. if (left < FZ.GameDefs.OFFSET_X) {
  549. this.m_div_line[index].style.left = 5 + "px";
  550. if (w > 3) {
  551. w -= 24;
  552. }
  553. }
  554. else
  555. if (left + w > FZ.GameDefs.SCREEN_W && w > 3) {
  556. w = 315 - left;
  557. this.m_div_line[index].style.left = left + "px";
  558. }
  559. else
  560. if (left > FZ.GameDefs.SCREEN_W) {
  561. this.m_div_line[index].style.left = 312 + "px";
  562. }
  563. else {
  564. this.m_div_line[index].style.left = left + "px";
  565. }
  566. if (top < FZ.GameDefs.OFFSET_Y) {
  567. this.m_div_line[index].style.top = 70 + "px";
  568. }
  569. else
  570. if (top + h > (FZ.GameDefs.SCREEN_H - FZ.GameDefs.SCREEN_BOTTOM_H) && h > 3) {
  571. h = FZ.GameDefs.SCREEN_H - FZ.GameDefs.SCREEN_BOTTOM_H - 5 - top;
  572. this.m_div_line[index].style.top = top + "px";
  573. }
  574. else
  575. if (top > (FZ.GameDefs.SCREEN_H - FZ.GameDefs.SCREEN_BOTTOM_H)) {
  576. this.m_div_line[index].style.top = (FZ.GameDefs.SCREEN_H - FZ.GameDefs.SCREEN_BOTTOM_H) - 5 + "px";
  577. if (resultH === true) {
  578. w += 3;
  579. }
  580. }
  581. else {
  582. this.m_div_line[index].style.top = top + "px";
  583. }
  584. this.m_div_line[index].style.width = w + "px";
  585. this.m_div_line[index].style.height = h + "px";
  586. this.m_div_line[index].style.zIndex = 100;
  587. // this.m_div_line[index].style.display = "inline";
  588. this.m_div_line[index].style.visibility = "visible";
  589. // this.m_allPets[this.m_PetFirstIndex].m_div.parentNode.appendChild(this.m_div_line[index]);
  590. }
  591. var that = this;
  592. that.m_reset_finished = false;
  593. setTimeout(function(){
  594. for (var index = 0; index < lineNum - 1; ++index) {
  595. // that.m_div_line[index].style.display = "none";
  596. that.m_div_line[index].style.visibility = "hidden";
  597. }
  598. }, 400);
  599. setTimeout(function(){
  600. that.resetPetPosEffect();
  601. if (that.getLeftPet() !== 0) {
  602. if (that.searchHasMatch() === false) {
  603. FZ.Game.GameState.m_isNoMatch = true;
  604. FZ.Game.GameState.levelCurrentTime = (new Date()).getTime();
  605. }
  606. }
  607. that.m_reset_finished = true;
  608. }, 600);
  609. this.m_left_pet -= 2;
  610. return true;
  611. }
  612. else {
  613. this.m_allPets[pet_index].setState(FZ.GameDefs.DREAMPET_FOCUS);
  614. if (this.m_firstPet) {
  615. this.m_firstPet.setState(FZ.GameDefs.DREAMPET_INIT);
  616. // this.m_firstPet.m_div_focus.style.display = "none";
  617. // this.m_firstPet.m_div_focus.style.visibility = "hidden";
  618. this.m_firstPet.hidden();
  619. if (this.m_secondPet) {
  620. this.m_secondPet.setState(FZ.GameDefs.DREAMPET_FOCUS);
  621. this.m_secondPet.show();
  622. this.m_firstPet = this.m_secondPet;
  623. }
  624. }
  625. return false;
  626. }
  627. // }//end if current pic not NULL
  628. },
  629. ABS: function(x, y){
  630. return ((x > y) ? (x - y) : (y - x));
  631. },
  632. updownReset: function(p1, p2){
  633. var lessId = 0;
  634. var greatId = 0;
  635. if (p1 > p2) {
  636. lessId = p1;
  637. greatId = p2;
  638. }
  639. else {
  640. lessId = p2;
  641. greatId = p1;
  642. }
  643. if (greatId > (FZ.GameDefs.DREAMPET_NUM_LINE_HALF + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  644. for (var index = greatId; index > (FZ.GameDefs.DREAMPET_NUM_LINE_HALF + 2) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  645. this.exchagePet(index, index - (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  646. }
  647. for (var index = lessId; index > (FZ.GameDefs.DREAMPET_NUM_LINE_HALF + 2) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  648. this.exchagePet(index, index - (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  649. }
  650. }
  651. else
  652. if (lessId > (FZ.GameDefs.DREAMPET_NUM_LINE_HALF + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2) &&
  653. greatId < (FZ.GameDefs.DREAMPET_NUM_LINE_HALF + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  654. for (var index = greatId; index < (FZ.GameDefs.DREAMPET_NUM_LINE_HALF) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  655. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  656. }
  657. for (var index = lessId; index > (FZ.GameDefs.DREAMPET_NUM_LINE_HALF + 2) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  658. this.exchagePet(index, index - (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  659. }
  660. }
  661. else {
  662. for (var index = lessId; index < (FZ.GameDefs.DREAMPET_NUM_LINE_HALF) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  663. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  664. }
  665. for (var index = greatId; index < (FZ.GameDefs.DREAMPET_NUM_LINE_HALF) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  666. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  667. }
  668. }
  669. },
  670. leftrightReset: function(p1, p2){
  671. var lessId = 0;
  672. var greatId = 0;
  673. if (p1 > p2) {
  674. lessId = p1;
  675. greatId = p2;
  676. }
  677. else {
  678. lessId = p2;
  679. greatId = p1;
  680. }
  681. var lessId_line = this.m_allPets[lessId].getLine();
  682. var lessId_col = this.m_allPets[lessId].getCol();
  683. var greatId_line = this.m_allPets[greatId].getLine();
  684. var greatId_col = this.m_allPets[greatId].getCol();
  685. if (lessId_col <= FZ.GameDefs.DREAMPET_NUM_COL_HALF && greatId_col <= FZ.GameDefs.DREAMPET_NUM_COL_HALF) {
  686. for (var index = lessId_col; index < FZ.GameDefs.DREAMPET_NUM_COL_HALF; index++) {
  687. this.exchagePet(lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index + 1);
  688. }
  689. for (var index = greatId_col; index < FZ.GameDefs.DREAMPET_NUM_COL_HALF; index++) {
  690. this.exchagePet(greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index + 1);
  691. }
  692. }
  693. else
  694. if (greatId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF && lessId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF) {
  695. for (var index = greatId_col; index > FZ.GameDefs.DREAMPET_NUM_COL_HALF + 1; index--) {
  696. this.exchagePet(greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index - 1);
  697. }
  698. for (var index = lessId_col; index > FZ.GameDefs.DREAMPET_NUM_COL_HALF + 1; index--) {
  699. this.exchagePet(lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index - 1);
  700. }
  701. }
  702. else
  703. if (greatId_col <= FZ.GameDefs.DREAMPET_NUM_COL_HALF && lessId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF) {
  704. for (var index = greatId_col; index < FZ.GameDefs.DREAMPET_NUM_COL_HALF; index++) {
  705. this.exchagePet(greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index + 1);
  706. }
  707. for (var index = lessId_col; index > FZ.GameDefs.DREAMPET_NUM_COL_HALF + 1; index--) {
  708. this.exchagePet(lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index - 1);
  709. }
  710. }
  711. else {
  712. for (var index = greatId_col; index > FZ.GameDefs.DREAMPET_NUM_COL_HALF + 1; index--) {
  713. this.exchagePet(greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index - 1);
  714. }
  715. for (var index = lessId_col; index < FZ.GameDefs.DREAMPET_NUM_COL_HALF; index++) {
  716. this.exchagePet(lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index + 1);
  717. }
  718. }
  719. },
  720. leftReset: function(p1, p2){
  721. var lessId = 0;
  722. var greatId = 0;
  723. if (p2 > p1) {
  724. lessId = p1;
  725. greatId = p2;
  726. }
  727. else {
  728. lessId = p2;
  729. greatId = p1;
  730. }
  731. var lessId_line = this.m_allPets[lessId].getLine();
  732. var lessId_col = this.m_allPets[lessId].getCol();
  733. var greatId_line = this.m_allPets[greatId].getLine();
  734. var greatId_col = this.m_allPets[greatId].getCol();
  735. for (var index = greatId_col; index < FZ.GameDefs.DREAMPET_NUM_COL; index++) {
  736. this.exchagePet(greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index + 1);
  737. }
  738. for (var index = lessId_col; index < FZ.GameDefs.DREAMPET_NUM_COL; index++) {
  739. this.exchagePet(lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index + 1);
  740. }
  741. },
  742. rightReset: function(p1, p2){
  743. var lessId = 0;
  744. var greatId = 0;
  745. if (p1 > p2) {
  746. lessId = p1;
  747. greatId = p2;
  748. }
  749. else {
  750. lessId = p2;
  751. greatId = p1;
  752. }
  753. var lessId_line = this.m_allPets[lessId].getLine();
  754. var lessId_col = this.m_allPets[lessId].getCol();
  755. var greatId_line = this.m_allPets[greatId].getLine();
  756. var greatId_col = this.m_allPets[greatId].getCol();
  757. for (var index = greatId_col; index > 0; index--) {
  758. if (index === 1) {
  759. break;
  760. }
  761. this.exchagePet(greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, greatId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index - 1);
  762. }
  763. for (var index = lessId_col; index > 0; index--) {
  764. if (index === 1) {
  765. break;
  766. }
  767. this.exchagePet(lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index, lessId_line * (FZ.GameDefs.DREAMPET_NUM_COL + 2) + index - 1);
  768. }
  769. },
  770. downReset: function(p1, p2){
  771. var tmp = 0;
  772. var lessId = 0;
  773. var greatId = 0;
  774. if (p1 > p2) {
  775. lessId = p1;
  776. greatId = p2;
  777. }
  778. else {
  779. lessId = p2;
  780. greatId = p1;
  781. }
  782. if ((lessId - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) < (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  783. return;
  784. }
  785. else
  786. if (((greatId - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) > (FZ.GameDefs.DREAMPET_NUM_COL + 2)) && ((greatId - lessId) % (FZ.GameDefs.DREAMPET_NUM_COL + 2) == 0)) {
  787. for (var index = greatId - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index > (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  788. this.exchagePet(index + (FZ.GameDefs.DREAMPET_NUM_COL + 2), index);
  789. tmp = index;
  790. }
  791. for (var index = lessId - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index >= tmp; index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  792. this.exchagePet(index + (FZ.GameDefs.DREAMPET_NUM_COL + 2), index);
  793. }
  794. }
  795. else {
  796. for (var index = lessId - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index > (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  797. this.exchagePet(index + (FZ.GameDefs.DREAMPET_NUM_COL + 2), index);
  798. }
  799. for (var index = greatId - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index > (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  800. this.exchagePet(index + (FZ.GameDefs.DREAMPET_NUM_COL + 2), index);
  801. }
  802. }
  803. },
  804. upReset: function(p1, p2){
  805. var tmp = 0;
  806. var lessId;
  807. var greatId;
  808. if (p1 > p2) {
  809. lessId = p1;
  810. greatId = p2;
  811. }
  812. else {
  813. lessId = p2;
  814. greatId = p1;
  815. }
  816. if (FZ.GameDefs.ALL_GENERAL - greatId - (FZ.GameDefs.DREAMPET_NUM_COL + 2) < (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  817. return;
  818. }
  819. else {
  820. for (var index = lessId; index + (FZ.GameDefs.DREAMPET_NUM_COL + 2) < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  821. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  822. }
  823. for (var index = greatId; index + (FZ.GameDefs.DREAMPET_NUM_COL + 2) < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  824. this.exchagePet(index + (FZ.GameDefs.DREAMPET_NUM_COL + 2), index);
  825. }
  826. }
  827. },
  828. centerReset: function(p1, p2){
  829. var tmp = 0;
  830. var lessId;
  831. var greatId;
  832. if (p2 > p1) {
  833. lessId = p1;
  834. greatId = p2;
  835. }
  836. else {
  837. lessId = p2;
  838. greatId = p1;
  839. }
  840. var lessId_line = this.m_allPets[lessId].getLine();
  841. var lessId_col = this.m_allPets[lessId].getCol();
  842. var greatId_line = this.m_allPets[greatId].getLine();
  843. var greatId_col = this.m_allPets[greatId].getCol();
  844. //special 1
  845. if (lessId_col <= FZ.GameDefs.DREAMPET_NUM_COL_HALF && lessId_line > FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  846. if (greatId_col <= FZ.GameDefs.DREAMPET_NUM_COL_HALF && greatId_line > FZ.GameDefs.DREAMPET_NUM_LINE_HALF &&
  847. (Math.floor((greatId - lessId) % (FZ.GameDefs.DREAMPET_NUM_COL + 2)) === 0 /*||(p2-p1)<FZ.GameDefs.DREAMPET_NUM_COL_HALF*/)) {
  848. tmp = greatId;
  849. for (var index = greatId; index > 0; index--) {
  850. if (this.m_allPets[index - 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  851. tmp = index;
  852. break;
  853. }
  854. else {
  855. this.exchagePet(index, index - 1);
  856. }
  857. }
  858. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  859. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  860. }
  861. tmp = lessId;
  862. for (var index = lessId; index > 0; index--) {
  863. if (this.m_allPets[index - 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  864. tmp = index;
  865. break;
  866. }
  867. else {
  868. this.exchagePet(index, index - 1);
  869. }
  870. }
  871. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  872. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  873. }
  874. return;
  875. }
  876. if (greatId_col <= FZ.GameDefs.DREAMPET_NUM_COL_HALF && greatId_line > FZ.GameDefs.DREAMPET_NUM_LINE_HALF &&
  877. Math.floor((greatId - lessId) % (FZ.GameDefs.DREAMPET_NUM_COL + 2)) === 0) {
  878. tmp = greatId;
  879. for (var index = greatId; index > 0; index--) {
  880. if (this.m_allPets[index - 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  881. tmp = index;
  882. break;
  883. }
  884. else {
  885. this.exchagePet(index, index - 1);
  886. }
  887. }
  888. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  889. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  890. }
  891. tmp = lessId;
  892. for (var index = lessId; index > 0; index--) {
  893. if (this.m_allPets[index - 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  894. tmp = index;
  895. break;
  896. }
  897. else {
  898. this.exchagePet(index, index - 1);
  899. }
  900. }
  901. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  902. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  903. }
  904. return;
  905. }
  906. }
  907. //special 2
  908. if (lessId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF && lessId_line <= FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  909. if (greatId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF && greatId_line <= FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  910. if ((greatId - lessId) < FZ.GameDefs.DREAMPET_NUM_COL_HALF) {
  911. tmp = greatId;
  912. for (var index = greatId; index < (greatId_line + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index++) {
  913. if (this.m_allPets[index + 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  914. tmp = index;
  915. break;
  916. }
  917. else {
  918. this.exchagePet(index, index + 1);
  919. }
  920. }
  921. for (var index = tmp; index > (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  922. if (this.m_allPets[index].getState() === FZ.GameDefs.DREAMPET_REMOVE &&
  923. this.m_allPets[index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  924. tmp = index;
  925. break;
  926. }
  927. this.exchagePet(index, index - (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  928. }
  929. tmp = lessId;
  930. for (var index = lessId; index < (lessId_line + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index++) {
  931. if (this.m_allPets[index + 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  932. tmp = index;
  933. break;
  934. }
  935. else {
  936. this.exchagePet(index, index + 1);
  937. }
  938. }
  939. for (var index = tmp; index > (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  940. if (this.m_allPets[index].getState() === FZ.GameDefs.DREAMPET_REMOVE &&
  941. this.m_allPets[index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  942. tmp = index;
  943. break;
  944. }
  945. this.exchagePet(index, index - (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  946. }
  947. return;
  948. }
  949. }
  950. }
  951. //special 3
  952. if (lessId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF && lessId_line > FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  953. if (greatId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF && greatId_line > FZ.GameDefs.DREAMPET_NUM_LINE_HALF &&
  954. (Math.floor((greatId - lessId) % (FZ.GameDefs.DREAMPET_NUM_COL + 2)) === 0 || (greatId - lessId) < FZ.GameDefs.DREAMPET_NUM_COL_HALF)) {
  955. tmp = greatId;
  956. for (var index = greatId; index < (greatId_line + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index++) {
  957. if (this.m_allPets[index + 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  958. tmp = index;
  959. break;
  960. }
  961. else {
  962. this.exchagePet(index, index + 1);
  963. }
  964. }
  965. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  966. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  967. }
  968. tmp = lessId;
  969. for (var index = lessId; index < (lessId_line + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index++) {
  970. if (this.m_allPets[index + 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  971. tmp = index;
  972. break;
  973. }
  974. else {
  975. this.exchagePet(index, index + 1);
  976. }
  977. }
  978. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  979. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  980. }
  981. return;
  982. }
  983. if (greatId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF && greatId_line > FZ.GameDefs.DREAMPET_NUM_LINE_HALF &&
  984. Math.floor((greatId - lessId) % (FZ.GameDefs.DREAMPET_NUM_COL + 2)) !== 0) {
  985. tmp = lessId;
  986. for (var index = lessId; index < (lessId_line + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index++) {
  987. if (this.m_allPets[index + 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  988. tmp = index;
  989. break;
  990. }
  991. else {
  992. this.exchagePet(index, index + 1);
  993. }
  994. }
  995. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  996. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  997. }
  998. tmp = greatId;
  999. for (var index = greatId; index < (greatId_line + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index++) {
  1000. if (this.m_allPets[index + 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  1001. tmp = index;
  1002. break;
  1003. }
  1004. else {
  1005. this.exchagePet(index, index + 1);
  1006. }
  1007. }
  1008. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  1009. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1010. }
  1011. return;
  1012. }
  1013. }
  1014. //lessId
  1015. tmp = lessId;
  1016. if (lessId_col <= FZ.GameDefs.DREAMPET_NUM_COL_HALF && lessId_line <= FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  1017. for (var index = lessId; index > 0; index--) {
  1018. if (this.m_allPets[index - 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  1019. tmp = index;
  1020. break;
  1021. }
  1022. else {
  1023. this.exchagePet(index, index - 1);
  1024. }
  1025. }
  1026. for (var index = tmp; index > (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  1027. if (this.m_allPets[index].getState() === FZ.GameDefs.DREAMPET_REMOVE &&
  1028. this.m_allPets[index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  1029. tmp = index;
  1030. break;
  1031. }
  1032. this.exchagePet(index, index - (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1033. }
  1034. }
  1035. else
  1036. if (lessId_col <= FZ.GameDefs.DREAMPET_NUM_COL_HALF && lessId_line > FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  1037. for (var index = lessId; index > 0; index--) {
  1038. if (this.m_allPets[index - 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  1039. tmp = index;
  1040. break;
  1041. }
  1042. else {
  1043. this.exchagePet(index, index - 1);
  1044. }
  1045. }
  1046. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  1047. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1048. }
  1049. }
  1050. else
  1051. if (lessId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF && lessId_line > FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  1052. for (var index = lessId; index < (lessId_line + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index++) {
  1053. if (this.m_allPets[index + 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  1054. tmp = index;
  1055. break;
  1056. }
  1057. else {
  1058. this.exchagePet(index, index + 1);
  1059. }
  1060. }
  1061. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  1062. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1063. }
  1064. }
  1065. else
  1066. if (lessId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF && lessId_line <= FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  1067. for (var index = lessId; index < (lessId_line + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index++) {
  1068. if (this.m_allPets[index + 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  1069. tmp = index;
  1070. break;
  1071. }
  1072. else {
  1073. this.exchagePet(index, index + 1);
  1074. }
  1075. }
  1076. for (var index = tmp; index > (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  1077. this.exchagePet(index, index - (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1078. }
  1079. }
  1080. tmp = greatId;
  1081. //greatId
  1082. if (greatId_col <= FZ.GameDefs.DREAMPET_NUM_COL_HALF && greatId_line <= FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  1083. for (var index = greatId; index > 0; index--) {
  1084. if (this.m_allPets[index - 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  1085. tmp = index;
  1086. break;
  1087. }
  1088. else {
  1089. this.exchagePet(index, index - 1);
  1090. }
  1091. }
  1092. for (var index = tmp; index > (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  1093. this.exchagePet(index, index - (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1094. }
  1095. }
  1096. else
  1097. if (greatId_col <= FZ.GameDefs.DREAMPET_NUM_COL_HALF && greatId_line > FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  1098. for (var index = greatId; index > 0; index--) {
  1099. if (this.m_allPets[index - 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  1100. tmp = index;
  1101. break;
  1102. }
  1103. else {
  1104. this.exchagePet(index, index - 1);
  1105. }
  1106. }
  1107. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  1108. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1109. }
  1110. }
  1111. else
  1112. if (greatId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF && greatId_line > FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  1113. for (var index = greatId; index < (greatId_line + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index++) {
  1114. if (this.m_allPets[index + 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  1115. tmp = index;
  1116. break;
  1117. }
  1118. else {
  1119. this.exchagePet(index, index + 1);
  1120. }
  1121. }
  1122. for (var index = tmp; index < FZ.GameDefs.ALL_GENERAL - (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index + (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  1123. this.exchagePet(index, index + (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1124. }
  1125. }
  1126. else
  1127. if (greatId_col > FZ.GameDefs.DREAMPET_NUM_COL_HALF && greatId_line <= FZ.GameDefs.DREAMPET_NUM_LINE_HALF) {
  1128. for (var index = greatId; index < (greatId_line + 1) * (FZ.GameDefs.DREAMPET_NUM_COL + 2); index++) {
  1129. if (this.m_allPets[index + 1].getState() === FZ.GameDefs.DREAMPET_REMOVE) {
  1130. tmp = index;
  1131. break;
  1132. }
  1133. else {
  1134. this.exchagePet(index, index + 1);
  1135. }
  1136. }
  1137. for (var index = tmp; index > (FZ.GameDefs.DREAMPET_NUM_COL + 2); index = index - (FZ.GameDefs.DREAMPET_NUM_COL + 2)) {
  1138. this.exchagePet(index, index - (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1139. }
  1140. }
  1141. },
  1142. exchagePet: function(firstPetIndex, secondPetIndex){
  1143. var firstCol = this.m_allPets[firstPetIndex].getCol();
  1144. var firstLine = this.m_allPets[firstPetIndex].getLine();
  1145. // var firstState = this.m_allPets[firstPetIndex].getState();
  1146. var secondCol = this.m_allPets[secondPetIndex].getCol();
  1147. var secondLine = this.m_allPets[secondPetIndex].getLine();
  1148. // var secondState = this.m_allPets[secondPetIndex].getState();
  1149. var tmpPet = null;
  1150. tmpPet = this.m_allPets[firstPetIndex];
  1151. this.m_allPets[firstPetIndex] = this.m_allPets[secondPetIndex];
  1152. this.m_allPets[firstPetIndex].setCol(firstCol);
  1153. this.m_allPets[firstPetIndex].setLine(firstLine);
  1154. //this.m_allPets[firstPetIndex].setState(firstState);
  1155. this.m_allPets[firstPetIndex].updatePos();
  1156. this.m_allPets[secondPetIndex] = tmpPet;
  1157. this.m_allPets[secondPetIndex].setCol(secondCol);
  1158. this.m_allPets[secondPetIndex].setLine(secondLine);
  1159. // this.m_allPets[secondPetIndex].setState(secondState);
  1160. this.m_allPets[secondPetIndex].updatePos();
  1161. this.m_allPets[firstPetIndex].setPetFocus();
  1162. this.m_allPets[secondPetIndex].setPetFocus();
  1163. },
  1164. getLeftPet: function(){
  1165. return this.m_left_pet;
  1166. },
  1167. getScore: function(){
  1168. return this.m_score;
  1169. },
  1170. setScore: function(score){
  1171. this.m_score = score;
  1172. },
  1173. getBonusTime: function(){
  1174. return this.m_bonus_time;
  1175. },
  1176. setBonusTime: function(time){
  1177. this.m_bonus_time = time;
  1178. },
  1179. onDrawPathLine: function(){
  1180. FZ.GameBase.MainContext.strokeStyle = '#ff0';
  1181. FZ.GameBase.MainContext.lineWidth = 3;
  1182. var tmpIndex = 0;
  1183. var temp = [];
  1184. for (var index = 0; index < (this.m_PointPath.length - 1); ++index) {
  1185. temp[1] = this.m_PointPath[index + 1][1];
  1186. temp[0] = this.m_PointPath[index + 1][0];
  1187. FZ.GameBase.MainContext.setTransform(this.m_worldMatrix.m11, this.m_worldMatrix.m12, this.m_worldMatrix.m21, this.m_worldMatrix.m22, this.m_worldMatrix.dx, this.m_worldMatrix.dy);
  1188. FZ.GameBase.MainContext.beginPath();
  1189. FZ.GameBase.MainContext.moveTo(FZ.GameDefs.DREAMPET_OFFSET_X + FZ.GameDefs.GRID_WIDTH * this.m_PointPath[index][0] + FZ.GameDefs.GRID_WIDTH_HALF, FZ.GameDefs.DREAMPET_OFFSET_Y + FZ.GameDefs.GRID_HEIGHT * this.m_PointPath[index][1] + FZ.GameDefs.GRID_HEIGHT_HALF);
  1190. FZ.GameBase.MainContext.lineTo(FZ.GameDefs.DREAMPET_OFFSET_X + FZ.GameDefs.GRID_WIDTH * temp[0] + FZ.GameDefs.GRID_WIDTH_HALF, FZ.GameDefs.DREAMPET_OFFSET_Y + FZ.GameDefs.GRID_HEIGHT * temp[1] + FZ.GameDefs.GRID_HEIGHT_HALF);
  1191. FZ.GameBase.MainContext.closePath();
  1192. FZ.GameBase.MainContext.stroke();
  1193. }
  1194. },
  1195. showPets: function(){
  1196. var tmp = null;
  1197. for (var index = 0; index < FZ.GameDefs.ALL_GENERAL; index++) {
  1198. tmp = this.m_allPets[index];
  1199. if (tmp.m_div) {
  1200. //tmp.m_div.style.display = "inline";
  1201. tmp.m_div.style.visibility = "visible";
  1202. if (FZ.GameDefs.DREAMPET_FOCUS === tmp.m_state) {
  1203. tmp.m_div_focus.style.visibility = "visible";
  1204. }
  1205. }
  1206. }
  1207. },
  1208. hidePets: function(){
  1209. var tmp = null;
  1210. for (var index = 0; index < FZ.GameDefs.ALL_GENERAL; index++) {
  1211. tmp = this.m_allPets[index];
  1212. if (tmp.m_div) {
  1213. // tmp.m_div.style.display = "none";
  1214. tmp.m_div.style.visibility = "hidden";
  1215. tmp.m_div_focus.style.visibility = "hidden";
  1216. }
  1217. }
  1218. },
  1219. resumeLevel: function(){
  1220. this.m_score = FZ.GameBase.SaveObject.m_cur_score;
  1221. this.m_hintCount = FZ.GameBase.SaveObject.m_cur_hintCount;
  1222. this.m_left_pet = FZ.GameBase.SaveObject.m_cur_left_pet;
  1223. this.m_level = FZ.GameBase.SaveObject.m_cur_level;
  1224. var index;
  1225. var tmp = null;
  1226. var tmpPetArr = null;
  1227. tmpPetArr = [];
  1228. var line = 0;
  1229. var col = 0;
  1230. var style = 0;
  1231. var state = FZ.GameDefs.DREAMPET_INIT;
  1232. this.clearAllPets();
  1233. for (index = 0; index < FZ.GameDefs.ALL_GENERAL; index++) {
  1234. state = FZ.GameBase.SaveObject.m_data[index].state;
  1235. style = FZ.GameBase.SaveObject.m_data[index].style;
  1236. line = Math.floor(index / (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1237. col = (index % (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1238. tmp = null;
  1239. tmp = new FZ.Diamond(line, col, style, state);
  1240. this.m_allPets.push(tmp);
  1241. if (FZ.GameDefs.DREAMPET_REMOVE !== state) {
  1242. this.m_parent.appendChild(tmp.m_div);
  1243. }
  1244. if (FZ.GameDefs.DREAMPET_FOCUS === state) {
  1245. this.m_firstPet = tmp;
  1246. }
  1247. }
  1248. },
  1249. saveLevel: function(){
  1250. FZ.GameBase.SaveObject.m_gamein = true;
  1251. FZ.GameBase.SaveObject.m_cur_score = this.m_score;
  1252. FZ.GameBase.SaveObject.m_cur_hintCount = this.m_hintCount;
  1253. FZ.GameBase.SaveObject.m_cur_left_pet = this.m_left_pet;
  1254. FZ.GameBase.SaveObject.m_level_usedTime = FZ.Game.GameState.m_level_usedTime;
  1255. if (FZ.TargetMobile !== FZ.TARGET_DEF.ANDRIOD) {
  1256. FZ.GameBase.SaveObject.m_sound = FZ.Game.GameState.m_sound;
  1257. }
  1258. var index;
  1259. var tmp = null;
  1260. var tmpPetArr = null;
  1261. tmpPetArr = FZ.GameBase.SaveObject.m_data;
  1262. for (index = 0; index < FZ.GameDefs.ALL_GENERAL; index++) {
  1263. // tmpPetArr[index].line = this.m_allPets[index].m_line;
  1264. // tmpPetArr[index].col = this.m_allPets[index].m_col;
  1265. tmpPetArr[index].style = this.m_allPets[index].m_style;
  1266. tmpPetArr[index].state = this.m_allPets[index].m_state;
  1267. }
  1268. // FZ.GameBase.SaveObject.m_data = tmpPetArr;
  1269. FZ.GameBase.saveGame();
  1270. },
  1271. initAllPets: function(isNew){
  1272. var line = 0;
  1273. var col = 0;
  1274. var style = 0;
  1275. var state = FZ.GameDefs.DREAMPET_INIT;
  1276. var index = 0;
  1277. var tmp = null;
  1278. var tmpPetArr = null;
  1279. tmpPetArr = tmpPetArr || [];
  1280. this.m_bonus_time = 0;
  1281. this.m_score = 0;
  1282. this.m_hintCount = FZ.GameDefs.LEVEL_HINT_NUMBER[this.getLevel()];
  1283. this.clearAllPets();
  1284. this.m_left_pet = FZ.GameDefs.ALL_PET_NUM;
  1285. var styleStart = 0;
  1286. var styleEnd = 0;
  1287. styleStart = FZ.Math.random(0, (FZ.GameDefs.DIAMOND_TYPES - FZ.GameDefs.LEVEL_PET_KIND[FZ.GameBase.SaveObject.m_cur_level]));
  1288. if (styleStart < 0) {
  1289. styleStart = 0;
  1290. }
  1291. styleEnd = styleStart + FZ.GameDefs.LEVEL_PET_KIND[FZ.GameBase.SaveObject.m_cur_level];
  1292. for (index = 0; index < FZ.GameDefs.ALL_GENERAL_HALF; index++) {
  1293. style = FZ.Math.random(styleStart, styleEnd);
  1294. state = FZ.GameDefs.DREAMPET_INIT;
  1295. line = Math.floor(index / (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1296. col = (index % (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1297. if (((line === 0) || (line === (FZ.GameDefs.DREAMPET_NUM_LINE + 1)) || (col === 0) || (col === (FZ.GameDefs.DREAMPET_NUM_COL + 1)))) {
  1298. state = FZ.GameDefs.DREAMPET_REMOVE;
  1299. style = -1;
  1300. }
  1301. tmp = null;
  1302. tmp = new FZ.Diamond(line, col, style, state);
  1303. // tmp.m_spr = this.m_sprite.clone();
  1304. this.m_allPets.push(tmp);
  1305. if (FZ.GameDefs.DREAMPET_REMOVE !== state) {
  1306. this.m_parent.appendChild(tmp.m_div);
  1307. }
  1308. tmpPetArr.push(tmp);
  1309. }
  1310. var tmpPet = null;
  1311. var tmpLen;
  1312. for (index = (FZ.GameDefs.ALL_GENERAL_HALF); index < (FZ.GameDefs.ALL_GENERAL); index++) {
  1313. tmpLen = Math.floor(FZ.Math.random(0, tmpPetArr.length));
  1314. // tmpPet = tmpPetArr.slice(tmpLen, tmpLen + 1);
  1315. state = FZ.GameDefs.DREAMPET_INIT;
  1316. style = tmpPetArr[tmpLen].getStyle();
  1317. //alert("style :" + style + ":" + "tmpLen :" + tmpLen);
  1318. // tmpPetArr.splice(tmpLen, 1);
  1319. line = Math.floor(index / (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1320. col = (index % (FZ.GameDefs.DREAMPET_NUM_COL + 2));
  1321. if (-1 === style) {
  1322. if (!((line === 0) || (line === (FZ.GameDefs.DREAMPET_NUM_LINE + 1)) || (col === 0) || (col === (FZ.GameDefs.DREAMPET_NUM_COL + 1)))) {
  1323. tmpLen = Math.floor(FZ.Math.random(0, tmpPetArr.length));
  1324. style = tmpPetArr[tmpLen].getStyle();
  1325. while (-1 === style) {
  1326. tmpLen = Math.floor(FZ.Math.random(0, tmpPetArr.length));
  1327. style = tmpPetArr[tmpLen].getStyle();
  1328. }
  1329. }
  1330. else {
  1331. state = FZ.GameDefs.DREAMPET_REMOVE;
  1332. style = -1;
  1333. }
  1334. }
  1335. else {
  1336. if (((line === 0) || (line === (FZ.GameDefs.DREAMPET_NUM_LINE + 1)) || (col === 0) || (col === (FZ.GameDefs.DREAMPET_NUM_COL + 1)))) {
  1337. tmpLen = Math.floor(FZ.Math.random(0, tmpPetArr.length));
  1338. style = tmpPetArr[tmpLen].getStyle();
  1339. while (-1 !== style) {
  1340. tmpLen = Math.floor(FZ.Math.random(0, tmpPetArr.length));
  1341. style = tmpPetArr[tmpLen].getStyle();
  1342. }
  1343. state = FZ.GameDefs.DREAMPET_REMOVE;
  1344. }
  1345. else {
  1346. }
  1347. }
  1348. tmpPetArr.splice(tmpLen, 1);
  1349. tmp = null;
  1350. tmp = new FZ.Diamond(line, col, style, state);
  1351. this.m_allPets.push(tmp);
  1352. if (FZ.GameDefs.DREAMPET_REMOVE !== state) {
  1353. this.m_parent.appendChild(tmp.m_div);
  1354. }
  1355. // this.m_parent.appendChild(tmp.m_div);
  1356. }
  1357. //this.debugAllPetsType();
  1358. this.m_leftNum = -1;
  1359. this.m_dialog = false;
  1360. },
  1361. debugAllPetsType: function(){
  1362. var index = 0;
  1363. debug_data = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 2, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1, 1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, ];
  1364. for (index = 0; index < (FZ.GameDefs.ALL_GENERAL); index++) {
  1365. if (-1 !== debug_data[index]) {
  1366. this.m_allPets[index].m_module = debug_data[index];
  1367. this.m_allPets[index].m_style = debug_data[index];
  1368. }
  1369. this.m_allPets[index].setModule();
  1370. if (-1 === debug_data[index]) {
  1371. this.m_allPets[index].m_state = -1;
  1372. }
  1373. else {
  1374. this.m_allPets[index].m_state = 0;
  1375. }
  1376. }
  1377. },
  1378. getDiamondNumber: function(col){
  1379. var number = 0;
  1380. var index = 0;
  1381. var tmp = null;
  1382. for (index = col; index < (FZ.GameDefs.ALL_GENERAL); index += FZ.GameDefs.DIAMOND_COL_NUM) {
  1383. tmp = this.m_allPets[index];
  1384. if (null !== tmp) {
  1385. number++;
  1386. }
  1387. }
  1388. return number;
  1389. },
  1390. getLeftDiamonds: function(){
  1391. var tmp = null;
  1392. var index = 0;
  1393. var leftNumber = 0;
  1394. for (index = 0; index < (FZ.GameDefs.ALL_GENERAL); index++) {
  1395. tmp = this.m_allPets[index];
  1396. if (!tmp) {
  1397. continue;
  1398. }
  1399. leftNumber++;
  1400. }
  1401. return leftNumber;
  1402. },
  1403. getLevel: function(){
  1404. return this.m_level;
  1405. },
  1406. setLevel: function(level){
  1407. this.m_level = level;
  1408. },
  1409. getHintCount: function(){
  1410. return this.m_hintCount;
  1411. },
  1412. setHintCount: function(hintCount){
  1413. this.m_hintCount = hintCount;
  1414. },
  1415. mouseHandler: function(evt){
  1416. // evt.stopPropagation();
  1417. // evt.preventDefault();
  1418. var petDisappear = false;
  1419. var type = "";
  1420. var x = 0;
  1421. var y = 0;
  1422. //var result = this.RESULT_NONE;
  1423. if (!this.m_reset_finished) {
  1424. return;
  1425. }
  1426. if (FZ.TARGET_DEF.MOBILE === FZ.TargetPort) {
  1427. if (FZ.EVENT_DEF.T_START === evt.type) {
  1428. type = FZ.EVENT_DEF.M_MOVE;
  1429. x = evt.touches[0].pageX - FZ.DivManager.getOffsetX();
  1430. y = evt.touches[0].pageY - FZ.DivManager.getOffsetY();
  1431. this.m_last_x = x;
  1432. this.m_last_y = y;
  1433. }
  1434. else
  1435. if (FZ.EVENT_DEF.T_MOVE === evt.type) {
  1436. type = FZ.EVENT_DEF.M_MOVE;
  1437. x = evt.touches[0].pageX - FZ.DivManager.getOffsetX();
  1438. y = evt.touches[0].pageY - FZ.DivManager.getOffsetY();
  1439. this.m_last_x = x;
  1440. this.m_last_y = y;
  1441. }
  1442. else
  1443. if (FZ.EVENT_DEF.T_END === evt.type) {
  1444. type = FZ.EVENT_DEF.M_CLICK;
  1445. x = this.m_last_x;
  1446. y = this.m_last_y;
  1447. this.m_last_x = 0;
  1448. this.m_last_y = 0;
  1449. }
  1450. }
  1451. else {
  1452. x = evt.pageX - FZ.DivManager.getOffsetX();
  1453. y = evt.pageY - FZ.DivManager.getOffsetY();
  1454. type = evt.type;
  1455. }
  1456. if (FZ.EVENT_DEF.M_MOVE === type) {
  1457. // result = this.startSearch(x, y);
  1458. // if(this.RESULT_CHANGED === result) {
  1459. //
  1460. // }//end if (this.RESULT_CHANGED === result) {
  1461. }//end if(this.EVT_MOUSE_MOVE === evt.type) {
  1462. else
  1463. if (FZ.EVENT_DEF.M_CLICK === type) {
  1464. petDisappear = this.setPetDisappear(x, y);
  1465. if (petDisappear === false) {
  1466. return;
  1467. }
  1468. // if(this.m_PetFirstIndex !== 0){
  1469. // this.m_timer = setTimeout(FZ.Tools.bind(this, this.wait1), 100);
  1470. // }
  1471. // this.setLabelText();
  1472. if ((this.m_observer) && this.m_observer.checkWin) {
  1473. // if(this.getDisplayPet() !== 0){
  1474. this.m_observer.checkWin();
  1475. // }
  1476. }
  1477. }
  1478. return false;
  1479. }
  1480. });
  1481. //
  1482. //