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

Java编程

开发平台:

Java

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