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

Java编程

开发平台:

Java

  1. public class Six extends Root
  2. {
  3. private GameTable gTable;
  4. private int x,y;
  5. private int direct=1;
  6. private int[] store;
  7. public Six()
  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]==0)&&
  14. (gTable.myTable[(gTable.x-1)/2+1][1]==0)&&(gTable.myTable[(gTable.x-1)/2+1][2]==0))
  15. {
  16. x=(gTable.x-1)/2;
  17. y=0;
  18. gTable.myTable[x][y]=1;
  19. gTable.myTable[x+1][y]=1;
  20. gTable.myTable[x+1][y+1]=1;
  21. gTable.myTable[x+1][y+2]=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+1];
  36. store[1]=gTable.myTable[x+1][y+3];
  37.         if(isGo(2))
  38.         {
  39. gTable.myTable[x][y]=0;
  40. gTable.myTable[x+1][y]=0;
  41. gTable.myTable[x][y+1]=1;
  42. gTable.myTable[x+1][y+3]=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+2];
  58.         store[1]=gTable.myTable[x+1][y+2];
  59. store[2]=gTable.myTable[x+2][y+2];
  60.         if(isGo(3))
  61.         {
  62. gTable.myTable[x+2][y]=0;
  63.          gTable.myTable[x][y+1]=0;
  64. gTable.myTable[x+1][y+1]=0;
  65. gTable.myTable[x][y+2]=1;
  66. gTable.myTable[x+1][y+2]=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]=0;
  87. gTable.myTable[x+1][y+2]=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+1];
  106. store[2]=gTable.myTable[x+2][y+1];
  107.         if(isGo(3))
  108.         {
  109. gTable.myTable[x][y]=0;
  110.          gTable.myTable[x+1][y]=0;
  111. gTable.myTable[x+2][y]=0;
  112. gTable.myTable[x][y+2]=1;
  113. gTable.myTable[x+1][y+1]=1;
  114. gTable.myTable[x+2][y+1]=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][y+1];
  138.         store[2]=gTable.myTable[x][y+2];
  139.         if(isGo(3))
  140.         {
  141. gTable.myTable[x+1][y]=0;
  142. gTable.myTable[x+1][y+1]=0;
  143. gTable.myTable[x+1][y+2]=0;
  144. gTable.myTable[x-1][y]=1;
  145. gTable.myTable[x][y+1]=1;
  146. gTable.myTable[x][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-1][y];
  184.         store[1]=gTable.myTable[x-1][y+1];
  185.         store[2]=gTable.myTable[x-1][y+2];
  186.         if(isGo(3))
  187.         {
  188. gTable.myTable[x][y]=0;
  189. gTable.myTable[x][y+1]=0;
  190. gTable.myTable[x+1][y+2]=0;
  191. gTable.myTable[x-1][y]=1;
  192. gTable.myTable[x-1][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+1]=0;
  213. gTable.myTable[x+2][y]=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+2][y+1];
  239.         store[2]=gTable.myTable[x+2][y+2];
  240.         if(isGo(3))
  241.         {
  242. gTable.myTable[x][y]=0;
  243. gTable.myTable[x+1][y+1]=0;
  244. gTable.myTable[x+1][y+2]=0;
  245. gTable.myTable[x+2][y]=1;
  246. gTable.myTable[x+2][y+1]=1;
  247. gTable.myTable[x+2][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+2][y]=0;
  267. gTable.myTable[x][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+1][y];
  285.         store[1]=gTable.myTable[x+1][y+1];
  286.         store[2]=gTable.myTable[x+2][y+2];
  287.         if(isGo(3))
  288.         {
  289. gTable.myTable[x][y]=0;
  290. gTable.myTable[x][y+1]=0;
  291. gTable.myTable[x][y+2]=0;
  292. gTable.myTable[x+1][y]=1;
  293. gTable.myTable[x+1][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+3][y];
  310. store[1]=gTable.myTable[x+1][y+1];
  311.         if(isGo(2))
  312.         {
  313. gTable.myTable[x][y]=0;
  314. gTable.myTable[x][y+1]=0;
  315. gTable.myTable[x+3][y]=1;
  316. gTable.myTable[x+1][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][y+1];
  339.         store[1]=gTable.myTable[x][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+1][y+1]=0;
  348. gTable.myTable[x][y+2]=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];
  367.         store[1]=gTable.myTable[x+1][y];
  368.         store[2]=gTable.myTable[x][y-1];
  369.         if(isGo(3))
  370.         {
  371. gTable.myTable[x+2][y]=0;
  372. gTable.myTable[x+2][y+1]=0;
  373. gTable.myTable[x][y]=1;
  374. gTable.myTable[x][y-1]=1;
  375. y-=1;
  376. direct=3;
  377. return true;
  378.     }
  379. else
  380. {
  381. return false;
  382. }
  383. }
  384. else
  385. {
  386. return false;
  387. }
  388. case 3:if(x<=gTable.x-3)
  389. {
  390.          store[0]=gTable.myTable[x+1][y];
  391.         store[1]=gTable.myTable[x+2][y];
  392.         store[2]=gTable.myTable[x+1][y+1];
  393.         store[3]=gTable.myTable[x+2][y+1];
  394.         if(isGo(4))
  395.         {
  396. gTable.myTable[x][y]=0;
  397. gTable.myTable[x+1][y+2]=0;
  398. gTable.myTable[x+1][y+1]=1;
  399. gTable.myTable[x+2][y+1]=1;
  400. y+=1;
  401. direct=4;
  402. return true;
  403.         }
  404.         else
  405.         {
  406. return false;
  407.       }
  408. }
  409. else
  410. {
  411. return false;
  412. }
  413. case 4:if(true)
  414. {
  415.         store[0]=gTable.myTable[x][y-1];
  416.         store[1]=gTable.myTable[x+1][y-1];
  417.         store[2]=gTable.myTable[x+1][y+1];
  418. store[3]=gTable.myTable[x+2][y+1];
  419.         if(isGo(4))
  420.         {
  421. gTable.myTable[x][y]=0;
  422. gTable.myTable[x+2][y]=0;
  423. gTable.myTable[x][y+1]=0;
  424. gTable.myTable[x][y-1]=1;
  425. gTable.myTable[x+1][y-1]=1;
  426. gTable.myTable[x+1][y+1]=1;
  427. y-=1;
  428. direct=1;
  429. return true;
  430.     }
  431. else
  432. {
  433. return false;
  434. }
  435. }
  436. else
  437. {
  438. return false;
  439. }
  440. default:return false;
  441. }
  442. }
  443. public void downTo()
  444. {
  445. boolean canDown=true;
  446. while(canDown)
  447. {
  448. canDown=down();
  449. }
  450. }
  451. public boolean isGo(int n)
  452. {
  453. for(int i=0;i<=(n-1);i++)
  454. {
  455. if(store[i]!=0)
  456. return false;
  457. }
  458. return true;
  459. }
  460. public static void main(String args[])
  461. {
  462. new Six();
  463. }
  464. }