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

Java编程

开发平台:

Java

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