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

Java编程

开发平台:

Java

  1. package russiagame;
  2. public class Four extends Root
  3. {
  4. private GameTable gTable;
  5. private int x,y;
  6. private int direct=1;
  7. private int[] store;
  8. public Four()
  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)&&
  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][y+1]=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+2];
  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+1]=0;
  42. gTable.myTable[x][y+2]=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+1];
  61.         if(isGo(3))
  62.         {
  63. gTable.myTable[x][y+1]=0;
  64.          gTable.myTable[x+1][y]=0;
  65. gTable.myTable[x+2][y]=0;
  66. gTable.myTable[x][y+2]=1;
  67. gTable.myTable[x+1][y+2]=1;
  68. gTable.myTable[x+2][y+1]=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-1][y];
  91.         store[1]=gTable.myTable[x-1][y+1];
  92.         store[2]=gTable.myTable[x][y+2];
  93.         if(isGo(3))
  94.         {
  95. gTable.myTable[x][y]=0;
  96. gTable.myTable[x+1][y+1]=0;
  97. gTable.myTable[x+1][y+2]=0;
  98. gTable.myTable[x-1][y]=1;
  99. gTable.myTable[x-1][y+1]=1;
  100. gTable.myTable[x][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][y];
  116. store[1]=gTable.myTable[x-1][y+1];
  117.         if(isGo(2))
  118.         {
  119. gTable.myTable[x+2][y]=0;
  120. gTable.myTable[x+1][y+1]=0;
  121. gTable.myTable[x][y]=1;
  122. gTable.myTable[x-1][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+1][y];
  145.         store[1]=gTable.myTable[x+2][y+1];
  146.         store[2]=gTable.myTable[x+2][y+2];
  147.         if(isGo(3))
  148.         {
  149. gTable.myTable[x][y]=0;
  150. gTable.myTable[x][y+1]=0;
  151. gTable.myTable[x+1][y+2]=0;
  152. gTable.myTable[x+1][y]=1;
  153. gTable.myTable[x+2][y+1]=1;
  154. gTable.myTable[x+2][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+3][y];
  170. store[1]=gTable.myTable[x+2][y+1];
  171.         if(isGo(2))
  172.         {
  173. gTable.myTable[x+1][y]=0;
  174. gTable.myTable[x][y+1]=0;
  175. gTable.myTable[x+3][y]=1;
  176. gTable.myTable[x+2][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-4)
  197. {
  198.          store[0]=gTable.myTable[x+1][y];
  199.         store[1]=gTable.myTable[x+2][y];
  200.         store[2]=gTable.myTable[x+3][y];
  201.         store[3]=gTable.myTable[x+2][y+2];
  202. store[4]=gTable.myTable[x+3][y+2];
  203. store[5]=gTable.myTable[x+2][y+3];
  204.         if(isGo(6))
  205.         {
  206. gTable.myTable[x][y]=0;
  207. gTable.myTable[x][y+1]=0;
  208. gTable.myTable[x+1][y+1]=0;
  209. gTable.myTable[x+2][y+1]=1;
  210. gTable.myTable[x+2][y+2]=1;
  211. gTable.myTable[x+3][y+1]=1;
  212. x+=1;
  213. y+=1;
  214. direct=2;
  215. return true;
  216.         }
  217.         else
  218.         {
  219. return false;
  220.       }
  221. }
  222. else
  223. {
  224. return false;
  225. }
  226. case 2:if(true)
  227. {
  228.         store[0]=gTable.myTable[x-1][y-1];
  229.         store[1]=gTable.myTable[x][y-1];
  230.         store[2]=gTable.myTable[x+1][y-1];
  231.         store[3]=gTable.myTable[x+2][y-1];
  232. store[4]=gTable.myTable[x][y];
  233. store[5]=gTable.myTable[x-1][y];
  234.         if(isGo(6))
  235.         {
  236. gTable.myTable[x+1][y]=0;
  237. gTable.myTable[x+2][y]=0;
  238. gTable.myTable[x+1][y+1]=0;
  239. gTable.myTable[x][y]=1;
  240. gTable.myTable[x-1][y]=1;
  241. gTable.myTable[x-1][y-1]=1;
  242. x-=1;
  243. y-=1;
  244. direct=1;
  245. return true;
  246.     }
  247. else
  248. {
  249. return false;
  250. }
  251. }
  252. else
  253. {
  254. return false;
  255. }
  256. default:return false;
  257. }
  258. }
  259. public void downTo()
  260. {
  261. boolean canDown=true;
  262. while(canDown)
  263. {
  264. canDown=down();
  265. }
  266. }
  267. public boolean isGo(int n)
  268. {
  269. for(int i=0;i<=(n-1);i++)
  270. {
  271. if(store[i]!=0)
  272. return false;
  273. }
  274. return true;
  275. }
  276. public static void main(String args[])
  277. {
  278. new Four();
  279. }
  280. }