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

Java编程

开发平台:

Java

  1. package russiagame;
  2. public class Three extends Root
  3. {
  4. private GameTable gTable;
  5. private int x,y;
  6. private int direct=1;
  7. private int[] store;
  8. public Three()
  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][2]==0)&&
  15. (gTable.myTable[(gTable.x-1)/2+1][0]==0)&&(gTable.myTable[(gTable.x-1)/2+1][1]==0))
  16. {
  17. x=(gTable.x-1)/2;
  18. y=0;
  19. gTable.myTable[x][y+1]=1;
  20. gTable.myTable[x][y+2]=1;
  21. gTable.myTable[x+1][y]=1;
  22. gTable.myTable[x+1][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-4)
  35.        {
  36.         store[0]=gTable.myTable[x][y+3];
  37. store[1]=gTable.myTable[x+1][y+2];
  38.         if(isGo(2))
  39.         {
  40. gTable.myTable[x][y+1]=0;
  41. gTable.myTable[x+1][y]=0;
  42. gTable.myTable[x][y+3]=1;
  43. gTable.myTable[x+1][y+2]=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+1];
  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][y]=0;
  64.          gTable.myTable[x+1][y]=0;
  65. gTable.myTable[x+2][y+1]=0;
  66. gTable.myTable[x][y+1]=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. default:return false;
  82. }
  83. }
  84. public boolean left()
  85. {
  86. switch(direct)
  87. {
  88. case 1:if(x>=1)
  89. {
  90.          store[0]=gTable.myTable[x][y];
  91.         store[1]=gTable.myTable[x-1][y+1];
  92.         store[2]=gTable.myTable[x-1][y+2];
  93.         if(isGo(3))
  94.         {
  95. gTable.myTable[x+1][y]=0;
  96. gTable.myTable[x+1][y+1]=0;
  97. gTable.myTable[x][y+2]=0;
  98. gTable.myTable[x][y]=1;
  99. gTable.myTable[x-1][y+1]=1;
  100. gTable.myTable[x-1][y+2]=1;
  101. x-=1;
  102. return true;
  103.         }
  104.         else
  105.         {
  106. return false;
  107.       }
  108. }
  109. else
  110. {
  111. return false;
  112. }
  113. case 2:if(x>=1)
  114. {
  115.         store[0]=gTable.myTable[x-1][y];
  116. store[1]=gTable.myTable[x][y+1];
  117.         if(isGo(2))
  118.         {
  119. gTable.myTable[x+1][y]=0;
  120. gTable.myTable[x+2][y+1]=0;
  121. gTable.myTable[x-1][y]=1;
  122. gTable.myTable[x][y+1]=1;
  123. x-=1;
  124. return true;
  125.     }
  126. else
  127. {
  128. return false;
  129. }
  130. }
  131. else
  132. {
  133. return false;
  134. }
  135. default:return false;
  136. }
  137. }
  138. public boolean right()
  139. {
  140. switch(direct)
  141. {
  142. case 1:if(x<=gTable.x-3)
  143. {
  144.          store[0]=gTable.myTable[x+2][y];
  145.         store[1]=gTable.myTable[x+2][y+1];
  146.         store[2]=gTable.myTable[x+1][y+2];
  147.         if(isGo(3))
  148.         {
  149. gTable.myTable[x][y+1]=0;
  150. gTable.myTable[x][y+2]=0;
  151. gTable.myTable[x+1][y]=0;
  152. gTable.myTable[x+2][y]=1;
  153. gTable.myTable[x+2][y+1]=1;
  154. gTable.myTable[x+1][y+2]=1;
  155. x+=1;
  156. return true;
  157.         }
  158.         else
  159.         {
  160. return false;
  161.       }
  162. }
  163. else
  164. {
  165. return false;
  166. }
  167. case 2:if(x<=gTable.x-4)
  168. {
  169.         store[0]=gTable.myTable[x+2][y];
  170. store[1]=gTable.myTable[x+3][y+1];
  171.         if(isGo(2))
  172.         {
  173. gTable.myTable[x][y]=0;
  174. gTable.myTable[x+1][y+1]=0;
  175. gTable.myTable[x+2][y]=1;
  176. gTable.myTable[x+3][y+1]=1;
  177. x+=1;
  178. return true;
  179.     }
  180. else
  181. {
  182. return false;
  183. }
  184. }
  185. else
  186. {
  187. return false;
  188. }
  189. default:return false;
  190. }
  191. }
  192. public boolean change()
  193. {
  194. switch(direct)
  195. {
  196. case 1:if(x<=gTable.x-3)
  197. {
  198.          store[0]=gTable.myTable[x+2][y];
  199.         store[1]=gTable.myTable[x+2][y+1];
  200.         store[2]=gTable.myTable[x+2][y+2];
  201.         store[3]=gTable.myTable[x+2][y+3];
  202. store[4]=gTable.myTable[x+1][y+2];
  203. store[5]=gTable.myTable[x+1][y+3];
  204.         if(isGo(6))
  205.         {
  206. gTable.myTable[x][y+1]=0;
  207. gTable.myTable[x+1][y]=0;
  208. gTable.myTable[x+1][y+1]=0;
  209. gTable.myTable[x+1][y+2]=1;
  210. gTable.myTable[x+1][y+3]=1;
  211. gTable.myTable[x+2][y+3]=1;
  212. y+=2;
  213. direct=2;
  214. return true;
  215.         }
  216.         else
  217.         {
  218. return false;
  219.       }
  220. }
  221. else
  222. {
  223. return false;
  224. }
  225. case 2:if(true)
  226. {
  227.         store[0]=gTable.myTable[x+2][y];
  228.         store[1]=gTable.myTable[x][y-1];
  229.         store[2]=gTable.myTable[x+1][y-1];
  230.         store[3]=gTable.myTable[x+2][y-1];
  231. store[4]=gTable.myTable[x+1][y-2];
  232. store[5]=gTable.myTable[x+2][y-2];
  233.         if(isGo(6))
  234.         {
  235. gTable.myTable[x+1][y]=0;
  236. gTable.myTable[x+1][y+1]=0;
  237. gTable.myTable[x+2][y+1]=0;
  238. gTable.myTable[x][y-1]=1;
  239. gTable.myTable[x+1][y-1]=1;
  240. gTable.myTable[x+1][y-2]=1;
  241. y-=2;
  242. direct=1;
  243. return true;
  244.     }
  245. else
  246. {
  247. return false;
  248. }
  249. }
  250. else
  251. {
  252. return false;
  253. }
  254. default:return false;
  255. }
  256. }
  257. public void downTo()
  258. {
  259. boolean canDown=true;
  260. while(canDown)
  261. {
  262. canDown=down();
  263. }
  264. }
  265. public boolean isGo(int n)
  266. {
  267. for(int i=0;i<=(n-1);i++)
  268. {
  269. if(store[i]!=0)
  270. return false;
  271. }
  272. return true;
  273. }
  274. public static void main(String args[])
  275. {
  276. new Three();
  277. }
  278. }