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

Java编程

开发平台:

Java

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