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

Java编程

开发平台:

Java

  1. public class Seven extends Root
  2. {
  3. private GameTable gTable;
  4. private int x,y;
  5. private int direct=1;
  6. private int[] store;
  7. public Seven()
  8. {
  9. store=new int[15];
  10. }
  11. public boolean begin()
  12. {
  13. if((gTable.myTable[(gTable.x-1)/2][1]==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+2][1]==0))
  15. {
  16. x=(gTable.x-1)/2;
  17. y=0;
  18. gTable.myTable[x][y+1]=1;
  19. gTable.myTable[x+1][y]=1;
  20. gTable.myTable[x+1][y+1]=1;
  21. gTable.myTable[x+2][y+1]=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-3)
  34.        {
  35.         store[0]=gTable.myTable[x][y+2];
  36. store[1]=gTable.myTable[x+1][y+2];
  37. store[2]=gTable.myTable[x+2][y+2];
  38.         if(isGo(3))
  39.         {
  40. gTable.myTable[x+1][y]=0;
  41. gTable.myTable[x][y+1]=0;
  42. gTable.myTable[x+2][y+1]=0;
  43. gTable.myTable[x][y+2]=1;
  44. gTable.myTable[x+1][y+2]=1;
  45. gTable.myTable[x+2][y+2]=1;
  46. y+=1;
  47. return true;
  48.         }
  49.         else
  50.         {
  51. return false;
  52.        }
  53. }
  54. else
  55. {
  56. return false;
  57. }
  58. case 2:if(y<=gTable.y-4)
  59. {
  60.         store[0]=gTable.myTable[x][y+3];
  61.         store[1]=gTable.myTable[x+1][y+2];
  62.         if(isGo(2))
  63.         {
  64. gTable.myTable[x][y]=0;
  65.          gTable.myTable[x+1][y+1]=0;
  66. gTable.myTable[x][y+3]=1;
  67. gTable.myTable[x+1][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-3)
  81.        {
  82.         store[0]=gTable.myTable[x][y+1];
  83. store[1]=gTable.myTable[x+1][y+2];
  84. store[2]=gTable.myTable[x+2][y+1];
  85.         if(isGo(3))
  86.         {
  87. gTable.myTable[x][y]=0;
  88. gTable.myTable[x+1][y]=0;
  89. gTable.myTable[x+2][y]=0;
  90. gTable.myTable[x][y+1]=1;
  91. gTable.myTable[x+1][y+2]=1;
  92. gTable.myTable[x+2][y+1]=1;
  93. y+=1;
  94. return true;
  95.         }
  96.         else
  97.         {
  98. return false;
  99.        }
  100. }
  101. else
  102. {
  103. return false;
  104. }
  105. case 4:if(y<=gTable.y-4)
  106. {
  107.         store[0]=gTable.myTable[x][y+2];
  108.         store[1]=gTable.myTable[x+1][y+3];
  109.         if(isGo(2))
  110.         {
  111. gTable.myTable[x+1][y]=0;
  112.          gTable.myTable[x][y+1]=0;
  113. gTable.myTable[x][y+2]=1;
  114. gTable.myTable[x+1][y+3]=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][y];
  137.         store[1]=gTable.myTable[x-1][y+1];
  138.         if(isGo(2))
  139.         {
  140. gTable.myTable[x+1][y]=0;
  141. gTable.myTable[x+2][y+1]=0;
  142. gTable.myTable[x][y]=1;
  143. gTable.myTable[x-1][y+1]=1;
  144. x-=1;
  145. return true;
  146.         }
  147.         else
  148.         {
  149. return false;
  150.       }
  151. }
  152. else
  153. {
  154. return false;
  155. }
  156. case 2:if(x>=1)
  157. {
  158.         store[0]=gTable.myTable[x-1][y];
  159. store[1]=gTable.myTable[x-1][y+1];
  160. store[2]=gTable.myTable[x-1][y+2];
  161.         if(isGo(3))
  162.         {
  163. gTable.myTable[x][y]=0;
  164. gTable.myTable[x+1][y+1]=0;
  165. gTable.myTable[x][y+2]=0;
  166. gTable.myTable[x-1][y]=1;
  167. gTable.myTable[x-1][y+1]=1;
  168. gTable.myTable[x-1][y+2]=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][y+1];
  185.         if(isGo(2))
  186.         {
  187. gTable.myTable[x+2][y]=0;
  188. gTable.myTable[x+1][y+1]=0;
  189. gTable.myTable[x-1][y]=1;
  190. gTable.myTable[x][y+1]=1;
  191. x-=1;
  192. return true;
  193.         }
  194.         else
  195.         {
  196. return false;
  197.       }
  198. }
  199. else
  200. {
  201. return false;
  202. }
  203. case 4:if(x>=1)
  204. {
  205.         store[0]=gTable.myTable[x][y];
  206. store[1]=gTable.myTable[x-1][y+1];
  207. store[2]=gTable.myTable[x][y+2];
  208.         if(isGo(3))
  209.         {
  210. gTable.myTable[x+1][y]=0;
  211. gTable.myTable[x+1][y+1]=0;
  212. gTable.myTable[x+1][y+2]=0;
  213. gTable.myTable[x][y]=1;
  214. gTable.myTable[x-1][y+1]=1;
  215. gTable.myTable[x][y+2]=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-4)
  236. {
  237.          store[0]=gTable.myTable[x+2][y];
  238.         store[1]=gTable.myTable[x+3][y+1];
  239.         if(isGo(2))
  240.         {
  241. gTable.myTable[x+1][y]=0;
  242. gTable.myTable[x][y+1]=0;
  243. gTable.myTable[x+2][y]=1;
  244. gTable.myTable[x+3][y+1]=1;
  245. x+=1;
  246. return true;
  247.         }
  248.         else
  249.         {
  250. return false;
  251.       }
  252. }
  253. else
  254. {
  255. return false;
  256. }
  257. case 2:if(x<=gTable.x-3)
  258. {
  259.         store[0]=gTable.myTable[x+1][y];
  260. store[1]=gTable.myTable[x+2][y+1];
  261. store[2]=gTable.myTable[x+1][y+2];
  262.         if(isGo(3))
  263.         {
  264. gTable.myTable[x][y]=0;
  265. gTable.myTable[x][y+1]=0;
  266. gTable.myTable[x][y+2]=0;
  267. gTable.myTable[x+1][y]=1;
  268. gTable.myTable[x+2][y+1]=1;
  269. gTable.myTable[x+1][y+2]=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-4)
  283. {
  284.          store[0]=gTable.myTable[x+3][y];
  285.         store[1]=gTable.myTable[x+2][y+1];
  286.         if(isGo(2))
  287.         {
  288. gTable.myTable[x][y]=0;
  289. gTable.myTable[x+1][y+1]=0;
  290. gTable.myTable[x+3][y]=1;
  291. gTable.myTable[x+2][y+1]=1;
  292. x+=1;
  293. return true;
  294.         }
  295.         else
  296.         {
  297. return false;
  298.       }
  299. }
  300. else
  301. {
  302. return false;
  303. }
  304. case 4:if(x<=gTable.x-3)
  305. {
  306.         store[0]=gTable.myTable[x+2][y];
  307. store[1]=gTable.myTable[x+2][y+1];
  308. store[2]=gTable.myTable[x+2][y+2];
  309.         if(isGo(3))
  310.         {
  311. gTable.myTable[x][y+1]=0;
  312. gTable.myTable[x+1][y]=0;
  313. gTable.myTable[x+1][y+2]=0;
  314. gTable.myTable[x+2][y]=1;
  315. gTable.myTable[x+2][y+1]=1;
  316. gTable.myTable[x+2][y+2]=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(true)
  337. {
  338.          store[0]=gTable.myTable[x][y];
  339.         store[1]=gTable.myTable[x][y-1];
  340.         store[2]=gTable.myTable[x+1][y-1];
  341.         if(isGo(3))
  342.         {
  343. gTable.myTable[x+1][y+1]=0;
  344. gTable.myTable[x+2][y+1]=0;
  345. gTable.myTable[x][y]=1;
  346. gTable.myTable[x][y-1]=1;
  347. y-=1;
  348. direct=2;
  349. return true;
  350.         }
  351.         else
  352.         {
  353. return false;
  354.       }
  355. }
  356. else
  357. {
  358. return false;
  359. }
  360. case 2:if(x<=gTable.x-3)
  361. {
  362.         store[0]=gTable.myTable[x+1][y];
  363.         store[1]=gTable.myTable[x+2][y];
  364.         store[2]=gTable.myTable[x+2][y+1];
  365.         store[3]=gTable.myTable[x+1][y+2];
  366.         if(isGo(4))
  367.         {
  368. gTable.myTable[x][y]=0;
  369. gTable.myTable[x][y+2]=0;
  370. gTable.myTable[x+2][y+1]=1;
  371. gTable.myTable[x+1][y+2]=1;
  372. y+=1;
  373. direct=3;
  374. return true;
  375.     }
  376. else
  377. {
  378. return false;
  379. }
  380. }
  381. else
  382. {
  383. return false;
  384. }
  385. case 3:if(true)
  386. {
  387.          store[0]=gTable.myTable[x][y-1];
  388.         store[1]=gTable.myTable[x+1][y-1];
  389.         store[2]=gTable.myTable[x+2][y-1];
  390. store[3]=gTable.myTable[x+2][y+1];
  391.         if(isGo(4))
  392.         {
  393. gTable.myTable[x][y]=0;
  394. gTable.myTable[x+1][y+1]=0;
  395. gTable.myTable[x+2][y-1]=1;
  396. gTable.myTable[x+2][y+1]=1;
  397. x+=1;
  398. y-=1;
  399. direct=4;
  400. return true;
  401.         }
  402.         else
  403.         {
  404. return false;
  405.       }
  406. }
  407. else
  408. {
  409. return false;
  410. }
  411. case 4:if(x<=gTable.x-3)
  412. {
  413.         store[0]=gTable.myTable[x+2][y];
  414.         store[1]=gTable.myTable[x+2][y+1];
  415.         store[2]=gTable.myTable[x+2][y+2];
  416.         store[3]=gTable.myTable[x][y+2];
  417.         if(isGo(4))
  418.         {
  419. gTable.myTable[x+1][y]=0;
  420. gTable.myTable[x][y+1]=0;
  421. gTable.myTable[x][y+2]=1;
  422. gTable.myTable[x+2][y+2]=1;
  423. y+=1;
  424. direct=1;
  425. return true;
  426.     }
  427. else
  428. {
  429. return false;
  430. }
  431. }
  432. else
  433. {
  434. return false;
  435. }
  436. default:return false;
  437. }
  438. }
  439. public void downTo()
  440. {
  441. boolean canDown=true;
  442. while(canDown)
  443. {
  444. canDown=down();
  445. }
  446. }
  447. public boolean isGo(int n)
  448. {
  449. for(int i=0;i<=(n-1);i++)
  450. {
  451. if(store[i]!=0)
  452. return false;
  453. }
  454. return true;
  455. }
  456. public static void main(String args[])
  457. {
  458. new Seven();
  459. }
  460. }