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

Java编程

开发平台:

Java

  1. package russiagame;
  2. public class One
  3.     extends Root { //第一个方块
  4.     private GameTable gTable; //创建游戏桌子
  5.     private int x, y; //方块坐上角现在在桌子上的位置
  6.     private int direct = 1; //第一个角度
  7.     private int[] store; //储存待判断是否可以移动的周围必要的坐标标志
  8.     public One() {
  9.         store = new int[15]; //15足够大了
  10.     }
  11.     public boolean begin() { //初始化显示
  12.         //判断用于初始化的坐标是否被占用
  13.         if ( (gTable.myTable[ (gTable.x - 1) / 2][0] == 0) &&
  14.             (gTable.myTable[ (gTable.x - 1) / 2][1] == 0) &&
  15.             (gTable.myTable[ (gTable.x - 1) / 2][2] == 0) &&
  16.             (gTable.myTable[ (gTable.x - 1) / 2][3] == 0)) {
  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][y + 2] = 1;
  22.             gTable.myTable[x][y + 3] = 1;
  23.             return true;
  24.         }
  25.         else {
  26.             return false; //初始化失败
  27.         }
  28.     }
  29.     public boolean down() { //向下移动
  30.         switch (direct) { //根据角度标志,其他方块有的有2个角度,有的有4个角度
  31.             case 1:
  32.                 if (y <= gTable.y - 5) { //是否在边缘
  33.                     store[0] = gTable.myTable[x][y + 4]; //储存待判断坐标
  34.                     if (isGo(1)) { //判断是否可移
  35.                         gTable.myTable[x][y] = 0; //将被移动坐标置0
  36.                         gTable.myTable[x][y + 4] = 1; //将目标坐标置1
  37.                         y += 1; //坐上角坐标移动
  38.                         return true;
  39.                     }
  40.                     else {
  41.                         return false; //移动失败
  42.                     }
  43.                 }
  44.                 else {
  45.                     return false; //移动失败
  46.                 }
  47.             case 2:
  48.                 if (y <= gTable.y - 2) { //同case 1
  49.                     store[0] = gTable.myTable[x][y + 1];
  50.                     store[1] = gTable.myTable[x + 1][y + 1];
  51.                     store[2] = gTable.myTable[x + 2][y + 1];
  52.                     store[3] = gTable.myTable[x + 3][y + 1];
  53.                     if (isGo(4)) {
  54.                         gTable.myTable[x][y] = 0;
  55.                         gTable.myTable[x + 1][y] = 0;
  56.                         gTable.myTable[x + 2][y] = 0;
  57.                         gTable.myTable[x + 3][y] = 0;
  58.                         gTable.myTable[x][y + 1] = 1;
  59.                         gTable.myTable[x + 1][y + 1] = 1;
  60.                         gTable.myTable[x + 2][y + 1] = 1;
  61.                         gTable.myTable[x + 3][y + 1] = 1;
  62.                         y += 1;
  63.                         return true;
  64.                     }
  65.                     else {
  66.                         return false;
  67.                     }
  68.                 }
  69.                 else {
  70.                     return false;
  71.                 }
  72.             default:
  73.                 return false;
  74.         }
  75.     }
  76.     public boolean left() { //同down()
  77.         switch (direct) {
  78.             case 1:
  79.                 if (x >= 1) {
  80.                     store[0] = gTable.myTable[x - 1][y];
  81.                     store[1] = gTable.myTable[x - 1][y + 1];
  82.                     store[2] = gTable.myTable[x - 1][y + 2];
  83.                     store[3] = gTable.myTable[x - 1][y + 3];
  84.                     if (isGo(4)) {
  85.                         gTable.myTable[x][y] = 0;
  86.                         gTable.myTable[x][y + 1] = 0;
  87.                         gTable.myTable[x][y + 2] = 0;
  88.                         gTable.myTable[x][y + 3] = 0;
  89.                         gTable.myTable[x - 1][y] = 1;
  90.                         gTable.myTable[x - 1][y + 1] = 1;
  91.                         gTable.myTable[x - 1][y + 2] = 1;
  92.                         gTable.myTable[x - 1][y + 3] = 1;
  93.                         x -= 1;
  94.                         return true;
  95.                     }
  96.                     else {
  97.                         return false;
  98.                     }
  99.                 }
  100.                 else {
  101.                     return false;
  102.                 }
  103.             case 2:
  104.                 if (x >= 1) {
  105.                     store[0] = gTable.myTable[x - 1][y];
  106.                     if (isGo(1)) {
  107.                         gTable.myTable[x + 3][y] = 0;
  108.                         gTable.myTable[x - 1][y] = 1;
  109.                         x -= 1;
  110.                         return true;
  111.                     }
  112.                     else {
  113.                         return false;
  114.                     }
  115.                 }
  116.                 else {
  117.                     return false;
  118.                 }
  119.             default:
  120.                 return false;
  121.         }
  122.     }
  123.     public boolean right() { //同down()
  124.         switch (direct) {
  125.             case 1:
  126.                 if (x <= gTable.x - 2) {
  127.                     store[0] = gTable.myTable[x + 1][y];
  128.                     store[1] = gTable.myTable[x + 1][y + 1];
  129.                     store[2] = gTable.myTable[x + 1][y + 2];
  130.                     store[3] = gTable.myTable[x + 1][y + 3];
  131.                     if (isGo(4)) {
  132.                         gTable.myTable[x][y] = 0;
  133.                         gTable.myTable[x][y + 1] = 0;
  134.                         gTable.myTable[x][y + 2] = 0;
  135.                         gTable.myTable[x][y + 3] = 0;
  136.                         gTable.myTable[x + 1][y] = 1;
  137.                         gTable.myTable[x + 1][y + 1] = 1;
  138.                         gTable.myTable[x + 1][y + 2] = 1;
  139.                         gTable.myTable[x + 1][y + 3] = 1;
  140.                         x += 1;
  141.                         return true;
  142.                     }
  143.                     else {
  144.                         return false;
  145.                     }
  146.                 }
  147.                 else {
  148.                     return false;
  149.                 }
  150.             case 2:
  151.                 if (x <= gTable.x - 5) {
  152.                     store[0] = gTable.myTable[x + 4][y];
  153.                     if (isGo(1)) {
  154.                         gTable.myTable[x][y] = 0;
  155.                         gTable.myTable[x + 4][y] = 1;
  156.                         x += 1;
  157.                         return true;
  158.                     }
  159.                     else {
  160.                         return false;
  161.                     }
  162.                 }
  163.                 else {
  164.                     return false;
  165.                 }
  166.             default:
  167.                 return false;
  168.         }
  169.     }
  170.     public boolean change() { //同down()
  171.         switch (direct) {
  172.             case 1:
  173.                 if (x <= gTable.x - 4) {
  174.                     store[0] = gTable.myTable[x + 1][y];
  175.                     store[1] = gTable.myTable[x + 1][y + 1];
  176.                     store[2] = gTable.myTable[x + 1][y + 2];
  177.                     store[3] = gTable.myTable[x + 1][y + 3];
  178.                     store[4] = gTable.myTable[x + 2][y];
  179.                     store[5] = gTable.myTable[x + 2][y + 1];
  180.                     store[6] = gTable.myTable[x + 2][y + 2];
  181.                     store[7] = gTable.myTable[x + 2][y + 3];
  182.                     store[8] = gTable.myTable[x + 3][y];
  183.                     store[9] = gTable.myTable[x + 3][y + 1];
  184.                     store[10] = gTable.myTable[x + 3][y + 2];
  185.                     store[11] = gTable.myTable[x + 3][y + 3];
  186.                     if (isGo(12)) {
  187.                         gTable.myTable[x][y] = 0;
  188.                         gTable.myTable[x][y + 1] = 0;
  189.                         gTable.myTable[x][y + 2] = 0;
  190.                         gTable.myTable[x + 1][y + 3] = 1;
  191.                         gTable.myTable[x + 2][y + 3] = 1;
  192.                         gTable.myTable[x + 3][y + 3] = 1;
  193.                         y += 3;
  194.                         direct = 2;
  195.                         return true;
  196.                     }
  197.                     else {
  198.                         return false;
  199.                     }
  200.                 }
  201.                 else {
  202.                     return false;
  203.                 }
  204.             case 2:
  205.                 if (true) {
  206.                     store[0] = gTable.myTable[x][y - 1];
  207.                     store[1] = gTable.myTable[x][y - 2];
  208.                     store[2] = gTable.myTable[x][y - 3];
  209.                     store[3] = gTable.myTable[x + 1][y - 1];
  210.                     store[4] = gTable.myTable[x + 1][y - 2];
  211.                     store[5] = gTable.myTable[x + 1][y - 3];
  212.                     store[6] = gTable.myTable[x + 2][y - 1];
  213.                     store[7] = gTable.myTable[x + 2][y - 2];
  214.                     store[8] = gTable.myTable[x + 2][y - 3];
  215.                     store[9] = gTable.myTable[x + 3][y - 1];
  216.                     store[10] = gTable.myTable[x + 3][y - 2];
  217.                     store[11] = gTable.myTable[x + 3][y - 3];
  218.                     if (isGo(12)) {
  219.                         gTable.myTable[x + 1][y] = 0;
  220.                         gTable.myTable[x + 2][y] = 0;
  221.                         gTable.myTable[x + 3][y] = 0;
  222.                         gTable.myTable[x][y - 3] = 1;
  223.                         gTable.myTable[x][y - 2] = 1;
  224.                         gTable.myTable[x][y - 1] = 1;
  225.                         y -= 3;
  226.                         direct = 1;
  227.                         return true;
  228.                     }
  229.                     else {
  230.                         return false;
  231.                     }
  232.                 }
  233.                 else {
  234.                     return false;
  235.                 }
  236.             default:
  237.                 return false;
  238.         }
  239.     }
  240.     public void downTo() { //一下到底
  241.         boolean canDown = true;
  242.         while (canDown) {
  243.             canDown = down(); //循环向下移动一格
  244.         }
  245.     }
  246.     public boolean isGo(int n) {
  247.         for (int i = 0; i <= (n - 1); i++) {
  248.             if (store[i] != 0) //如果有占位则失败
  249.                 return false;
  250.         }
  251.         return true;
  252.     }
  253.     public static void main(String args[]) {
  254.         new One();
  255.     }
  256. }