Five.java~1~
上传用户:liming9091
上传日期:2014-10-27
资源大小:3376k
文件大小:10k
源码类别:

Java编程

开发平台:

Java

  1. public class Five extends Root
  2. {
  3. private GameTable gTable;
  4. private int x,y;
  5. private int direct=1;
  6. private int[] store;
  7. public Five()
  8. {
  9. store=new int[15];
  10. }
  11. public boolean begin()
  12. {
  13. if((gTable.myTable[(gTable.x-1)/2][0]==0)&&(gTable.myTable[(gTable.x-1)/2][1]==0)&&
  14. (gTable.myTable[(gTable.x-1)/2][2]==0)&&(gTable.myTable[(gTable.x-1)/2+1][0]==0))
  15. {
  16. x=(gTable.x-1)/2;
  17. y=0;
  18. gTable.myTable[x][y]=1;
  19. gTable.myTable[x][y+1]=1;
  20. gTable.myTable[x][y+2]=1;
  21. gTable.myTable[x+1][y]=1;
  22. return true;
  23. }
  24. else
  25. {
  26. return false;
  27. }
  28. }
  29. public boolean down()
  30. {
  31. switch(direct)
  32. {
  33.                  case 1:if(y<=gTable.y-4)
  34.        {
  35.         store[0]=gTable.myTable[x][y+3];
  36. store[1]=gTable.myTable[x+1][y+1];
  37.         if(isGo(2))
  38.         {
  39. gTable.myTable[x][y]=0;
  40. gTable.myTable[x+1][y]=0;
  41. gTable.myTable[x][y+3]=1;
  42. gTable.myTable[x+1][y+1]=1;
  43. y+=1;
  44. return true;
  45.         }
  46.         else
  47.         {
  48. return false;
  49.        }
  50. }
  51. else
  52. {
  53. return false;
  54. }
  55. case 2:if(y<=gTable.y-3)
  56. {
  57.         store[0]=gTable.myTable[x][y+1];
  58.         store[1]=gTable.myTable[x+1][y+1];
  59. store[2]=gTable.myTable[x+2][y+2];
  60.         if(isGo(3))
  61.         {
  62. gTable.myTable[x][y]=0;
  63.          gTable.myTable[x+1][y]=0;
  64. gTable.myTable[x+2][y]=0;
  65. gTable.myTable[x][y+1]=1;
  66. gTable.myTable[x+1][y+1]=1;
  67. gTable.myTable[x+2][y+2]=1;
  68. y+=1;
  69. return true;
  70.     }
  71. else
  72. {
  73. return false;
  74. }
  75. }
  76. else
  77. {
  78. return false;
  79. }
  80. case 3:if(y<=gTable.y-4)
  81.        {
  82.         store[0]=gTable.myTable[x][y+3];
  83. store[1]=gTable.myTable[x+1][y+3];
  84.         if(isGo(2))
  85.         {
  86. gTable.myTable[x][y+2]=0;
  87. gTable.myTable[x+1][y]=0;
  88. gTable.myTable[x][y+3]=1;
  89. gTable.myTable[x+1][y+3]=1;
  90. y+=1;
  91. return true;
  92.         }
  93.         else
  94.         {
  95. return false;
  96.        }
  97. }
  98. else
  99. {
  100. return false;
  101. }
  102. case 4:if(y<=gTable.y-3)
  103. {
  104.         store[0]=gTable.myTable[x][y+2];
  105.         store[1]=gTable.myTable[x+1][y+2];
  106. store[2]=gTable.myTable[x+2][y+2];
  107.         if(isGo(3))
  108.         {
  109. gTable.myTable[x][y]=0;
  110.          gTable.myTable[x+1][y+1]=0;
  111. gTable.myTable[x+2][y+1]=0;
  112. gTable.myTable[x][y+2]=1;
  113. gTable.myTable[x+1][y+2]=1;
  114. gTable.myTable[x+2][y+2]=1;
  115. y+=1;
  116. return true;
  117.     }
  118. else
  119. {
  120. return false;
  121. }
  122. }
  123. else
  124. {
  125. return false;
  126. }
  127. default:return false;
  128. }
  129. }
  130. public boolean left()
  131. {
  132. switch(direct)
  133. {
  134. case 1:if(x>=1)
  135. {
  136.          store[0]=gTable.myTable[x-1][y];
  137.         store[1]=gTable.myTable[x-1][y+1];
  138.         store[2]=gTable.myTable[x-1][y+2];
  139.         if(isGo(3))
  140.         {
  141. gTable.myTable[x+1][y]=0;
  142. gTable.myTable[x][y+1]=0;
  143. gTable.myTable[x][y+2]=0;
  144. gTable.myTable[x-1][y]=1;
  145. gTable.myTable[x-1][y+1]=1;
  146. gTable.myTable[x-1][y+2]=1;
  147. x-=1;
  148. return true;
  149.         }
  150.         else
  151.         {
  152. return false;
  153.       }
  154. }
  155. else
  156. {
  157. return false;
  158. }
  159. case 2:if(x>=1)
  160. {
  161.         store[0]=gTable.myTable[x-1][y];
  162. store[1]=gTable.myTable[x+1][y+1];
  163.         if(isGo(2))
  164.         {
  165. gTable.myTable[x+2][y]=0;
  166. gTable.myTable[x+2][y+1]=0;
  167. gTable.myTable[x-1][y]=1;
  168. gTable.myTable[x+1][y+1]=1;
  169. x-=1;
  170. return true;
  171.     }
  172. else
  173. {
  174. return false;
  175. }
  176. }
  177. else
  178. {
  179. return false;
  180. }
  181. case 3:if(x>=1)
  182. {
  183.          store[0]=gTable.myTable[x][y];
  184.         store[1]=gTable.myTable[x][y+1];
  185.         store[2]=gTable.myTable[x-1][y+2];
  186.         if(isGo(3))
  187.         {
  188. gTable.myTable[x+1][y]=0;
  189. gTable.myTable[x+1][y+1]=0;
  190. gTable.myTable[x+1][y+2]=0;
  191. gTable.myTable[x][y]=1;
  192. gTable.myTable[x][y+1]=1;
  193. gTable.myTable[x-1][y+2]=1;
  194. x-=1;
  195. return true;
  196.         }
  197.         else
  198.         {
  199. return false;
  200.       }
  201. }
  202. else
  203. {
  204. return false;
  205. }
  206. case 4:if(x>=1)
  207. {
  208.         store[0]=gTable.myTable[x-1][y];
  209. store[1]=gTable.myTable[x-1][y+1];
  210.         if(isGo(2))
  211.         {
  212. gTable.myTable[x][y]=0;
  213. gTable.myTable[x+2][y+1]=0;
  214. gTable.myTable[x-1][y]=1;
  215. gTable.myTable[x-1][y+1]=1;
  216. x-=1;
  217. return true;
  218.     }
  219. else
  220. {
  221. return false;
  222. }
  223. }
  224. else
  225. {
  226. return false;
  227. }
  228. default:return false;
  229. }
  230. }
  231. public boolean right()
  232. {
  233. switch(direct)
  234. {
  235. case 1:if(x<=gTable.x-3)
  236. {
  237.          store[0]=gTable.myTable[x+2][y];
  238.         store[1]=gTable.myTable[x+1][y+1];
  239.         store[2]=gTable.myTable[x+1][y+2];
  240.         if(isGo(3))
  241.         {
  242. gTable.myTable[x][y]=0;
  243. gTable.myTable[x][y+1]=0;
  244. gTable.myTable[x][y+2]=0;
  245. gTable.myTable[x+2][y]=1;
  246. gTable.myTable[x+1][y+1]=1;
  247. gTable.myTable[x+1][y+2]=1;
  248. x+=1;
  249. return true;
  250.         }
  251.         else
  252.         {
  253. return false;
  254.       }
  255. }
  256. else
  257. {
  258. return false;
  259. }
  260. case 2:if(x<=gTable.x-4)
  261. {
  262.         store[0]=gTable.myTable[x+3][y];
  263. store[1]=gTable.myTable[x+3][y+1];
  264.         if(isGo(2))
  265.         {
  266. gTable.myTable[x][y]=0;
  267. gTable.myTable[x+2][y+1]=0;
  268. gTable.myTable[x+3][y]=1;
  269. gTable.myTable[x+3][y+1]=1;
  270. x+=1;
  271. return true;
  272.     }
  273. else
  274. {
  275. return false;
  276. }
  277. }
  278. else
  279. {
  280. return false;
  281. }
  282. case 3:if(x<=gTable.x-3)
  283. {
  284.          store[0]=gTable.myTable[x+2][y];
  285.         store[1]=gTable.myTable[x+2][y+1];
  286.         store[2]=gTable.myTable[x+2][y+2];
  287.         if(isGo(3))
  288.         {
  289. gTable.myTable[x][y+2]=0;
  290. gTable.myTable[x+1][y]=0;
  291. gTable.myTable[x+1][y+1]=0;
  292. gTable.myTable[x+2][y]=1;
  293. gTable.myTable[x+2][y+1]=1;
  294. gTable.myTable[x+2][y+2]=1;
  295. x+=1;
  296. return true;
  297.         }
  298.         else
  299.         {
  300. return false;
  301.       }
  302. }
  303. else
  304. {
  305. return false;
  306. }
  307. case 4:if(x<=gTable.x-4)
  308. {
  309.         store[0]=gTable.myTable[x+1][y];
  310. store[1]=gTable.myTable[x+3][y+1];
  311.         if(isGo(2))
  312.         {
  313. gTable.myTable[x][y]=0;
  314. gTable.myTable[x][y+1]=0;
  315. gTable.myTable[x+1][y]=1;
  316. gTable.myTable[x+3][y+1]=1;
  317. x+=1;
  318. return true;
  319.     }
  320. else
  321. {
  322. return false;
  323. }
  324. }
  325. else
  326. {
  327. return false;
  328. }
  329. default:return false;
  330. }
  331. }
  332. public boolean change()
  333. {
  334. switch(direct)
  335. {
  336. case 1:if(x<=gTable.x-3)
  337. {
  338.          store[0]=gTable.myTable[x+1][y+1];
  339.         store[1]=gTable.myTable[x+1][y+2];
  340.         store[2]=gTable.myTable[x+2][y];
  341.         store[3]=gTable.myTable[x+2][y+1];
  342. store[4]=gTable.myTable[x+2][y+2];
  343.         if(isGo(5))
  344.         {
  345. gTable.myTable[x][y]=0;
  346. gTable.myTable[x+1][y]=0;
  347. gTable.myTable[x][y+2]=0;
  348. gTable.myTable[x+1][y+1]=1;
  349. gTable.myTable[x+2][y+1]=1;
  350. gTable.myTable[x+2][y+2]=1;
  351. y+=1;
  352. direct=2;
  353. return true;
  354.         }
  355.         else
  356.         {
  357. return false;
  358.       }
  359. }
  360. else
  361. {
  362. return false;
  363. }
  364. case 2:if(true)
  365. {
  366.         store[0]=gTable.myTable[x][y-1];
  367.         store[1]=gTable.myTable[x+1][y-1];
  368.         store[2]=gTable.myTable[x+2][y-1];
  369.         store[3]=gTable.myTable[x][y+1];
  370. store[4]=gTable.myTable[x+1][y+1];
  371.         if(isGo(5))
  372.         {
  373. gTable.myTable[x][y]=0;
  374. gTable.myTable[x+2][y]=0;
  375. gTable.myTable[x+2][y+1]=0;
  376. gTable.myTable[x+1][y-1]=1;
  377. gTable.myTable[x][y+1]=1;
  378. gTable.myTable[x+1][y+1]=1;
  379. y-=1;
  380. direct=3;
  381. return true;
  382.     }
  383. else
  384. {
  385. return false;
  386. }
  387. }
  388. else
  389. {
  390. return false;
  391. }
  392. case 3:if(x<=gTable.x-3)
  393. {
  394.          store[0]=gTable.myTable[x+2][y];
  395.         store[1]=gTable.myTable[x+2][y+1];
  396.         store[2]=gTable.myTable[x+2][y+2];
  397.         store[3]=gTable.myTable[x][y+1];
  398.         if(isGo(4))
  399.         {
  400. gTable.myTable[x+1][y]=0;
  401. gTable.myTable[x+1][y+1]=0;
  402. gTable.myTable[x][y+1]=1;
  403. gTable.myTable[x+2][y+2]=1;
  404. y+=1;
  405. direct=4;
  406. return true;
  407.         }
  408.         else
  409.         {
  410. return false;
  411.       }
  412. }
  413. else
  414. {
  415. return false;
  416. }
  417. case 4:if(true)
  418. {
  419.         store[0]=gTable.myTable[x][y-1];
  420.         store[1]=gTable.myTable[x+1][y-1];
  421.         store[2]=gTable.myTable[x+1][y];
  422.         if(isGo(3))
  423.         {
  424. gTable.myTable[x+1][y+1]=0;
  425. gTable.myTable[x+2][y+1]=0;
  426. gTable.myTable[x][y-1]=1;
  427. gTable.myTable[x+1][y-1]=1;
  428. y-=1;
  429. direct=1;
  430. return true;
  431.     }
  432. else
  433. {
  434. return false;
  435. }
  436. }
  437. else
  438. {
  439. return false;
  440. }
  441. default:return false;
  442. }
  443. }
  444. public void downTo()
  445. {
  446. boolean canDown=true;
  447. while(canDown)
  448. {
  449. canDown=down();
  450. }
  451. }
  452. public boolean isGo(int n)
  453. {
  454. for(int i=0;i<=(n-1);i++)
  455. {
  456. if(store[i]!=0)
  457. return false;
  458. }
  459. return true;
  460. }
  461. public static void main(String args[])
  462. {
  463. new Five();
  464. }
  465. }