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

Java编程

开发平台:

Java

  1. package russiagame;
  2. public class Seven extends Root {
  3.     private GameTable gTable;
  4.     private int x, y;
  5.     private int direct = 1;
  6.     private int[] store;
  7.     public Seven() {
  8.         store = new int[15];
  9.     }
  10.     public boolean begin() {
  11.         if ( (gTable.myTable[ (gTable.x - 1) / 2][1] == 0) &&
  12.             (gTable.myTable[ (gTable.x - 1) / 2 + 1][0] == 0) &&
  13.             (gTable.myTable[ (gTable.x - 1) / 2 + 1][1] == 0) &&
  14.             (gTable.myTable[ (gTable.x - 1) / 2 + 2][1] == 0)) {
  15.             x = (gTable.x - 1) / 2;
  16.             y = 0;
  17.             gTable.myTable[x][y + 1] = 1;
  18.             gTable.myTable[x + 1][y] = 1;
  19.             gTable.myTable[x + 1][y + 1] = 1;
  20.             gTable.myTable[x + 2][y + 1] = 1;
  21.             return true;
  22.         }
  23.         else {
  24.             return false;
  25.         }
  26.     }
  27.     public boolean down() {
  28.         switch (direct) {
  29.             case 1:
  30.                 if (y <= gTable.y - 3) {
  31.                     store[0] = gTable.myTable[x][y + 2];
  32.                     store[1] = gTable.myTable[x + 1][y + 2];
  33.                     store[2] = gTable.myTable[x + 2][y + 2];
  34.                     if (isGo(3)) {
  35.                         gTable.myTable[x + 1][y] = 0;
  36.                         gTable.myTable[x][y + 1] = 0;
  37.                         gTable.myTable[x + 2][y + 1] = 0;
  38.                         gTable.myTable[x][y + 2] = 1;
  39.                         gTable.myTable[x + 1][y + 2] = 1;
  40.                         gTable.myTable[x + 2][y + 2] = 1;
  41.                         y += 1;
  42.                         return true;
  43.                     }
  44.                     else {
  45.                         return false;
  46.                     }
  47.                 }
  48.                 else {
  49.                     return false;
  50.                 }
  51.             case 2:
  52.                 if (y <= gTable.y - 4) {
  53.                     store[0] = gTable.myTable[x][y + 3];
  54.                     store[1] = gTable.myTable[x + 1][y + 2];
  55.                     if (isGo(2)) {
  56.                         gTable.myTable[x][y] = 0;
  57.                         gTable.myTable[x + 1][y + 1] = 0;
  58.                         gTable.myTable[x][y + 3] = 1;
  59.                         gTable.myTable[x + 1][y + 2] = 1;
  60.                         y += 1;
  61.                         return true;
  62.                     }
  63.                     else {
  64.                         return false;
  65.                     }
  66.                 }
  67.                 else {
  68.                     return false;
  69.                 }
  70.             case 3:
  71.                 if (y <= gTable.y - 3) {
  72.                     store[0] = gTable.myTable[x][y + 1];
  73.                     store[1] = gTable.myTable[x + 1][y + 2];
  74.                     store[2] = gTable.myTable[x + 2][y + 1];
  75.                     if (isGo(3)) {
  76.                         gTable.myTable[x][y] = 0;
  77.                         gTable.myTable[x + 1][y] = 0;
  78.                         gTable.myTable[x + 2][y] = 0;
  79.                         gTable.myTable[x][y + 1] = 1;
  80.                         gTable.myTable[x + 1][y + 2] = 1;
  81.                         gTable.myTable[x + 2][y + 1] = 1;
  82.                         y += 1;
  83.                         return true;
  84.                     }
  85.                     else {
  86.                         return false;
  87.                     }
  88.                 }
  89.                 else {
  90.                     return false;
  91.                 }
  92.             case 4:
  93.                 if (y <= gTable.y - 4) {
  94.                     store[0] = gTable.myTable[x][y + 2];
  95.                     store[1] = gTable.myTable[x + 1][y + 3];
  96.                     if (isGo(2)) {
  97.                         gTable.myTable[x + 1][y] = 0;
  98.                         gTable.myTable[x][y + 1] = 0;
  99.                         gTable.myTable[x][y + 2] = 1;
  100.                         gTable.myTable[x + 1][y + 3] = 1;
  101.                         y += 1;
  102.                         return true;
  103.                     }
  104.                     else {
  105.                         return false;
  106.                     }
  107.                 }
  108.                 else {
  109.                     return false;
  110.                 }
  111.             default:
  112.                 return false;
  113.         }
  114.     }
  115.     public boolean left() {
  116.         switch (direct) {
  117.             case 1:
  118.                 if (x >= 1) {
  119.                     store[0] = gTable.myTable[x][y];
  120.                     store[1] = gTable.myTable[x - 1][y + 1];
  121.                     if (isGo(2)) {
  122.                         gTable.myTable[x + 1][y] = 0;
  123.                         gTable.myTable[x + 2][y + 1] = 0;
  124.                         gTable.myTable[x][y] = 1;
  125.                         gTable.myTable[x - 1][y + 1] = 1;
  126.                         x -= 1;
  127.                         return true;
  128.                     }
  129.                     else {
  130.                         return false;
  131.                     }
  132.                 }
  133.                 else {
  134.                     return false;
  135.                 }
  136.             case 2:
  137.                 if (x >= 1) {
  138.                     store[0] = gTable.myTable[x - 1][y];
  139.                     store[1] = gTable.myTable[x - 1][y + 1];
  140.                     store[2] = gTable.myTable[x - 1][y + 2];
  141.                     if (isGo(3)) {
  142.                         gTable.myTable[x][y] = 0;
  143.                         gTable.myTable[x + 1][y + 1] = 0;
  144.                         gTable.myTable[x][y + 2] = 0;
  145.                         gTable.myTable[x - 1][y] = 1;
  146.                         gTable.myTable[x - 1][y + 1] = 1;
  147.                         gTable.myTable[x - 1][y + 2] = 1;
  148.                         x -= 1;
  149.                         return true;
  150.                     }
  151.                     else {
  152.                         return false;
  153.                     }
  154.                 }
  155.                 else {
  156.                     return false;
  157.                 }
  158.             case 3:
  159.                 if (x >= 1) {
  160.                     store[0] = gTable.myTable[x - 1][y];
  161.                     store[1] = gTable.myTable[x][y + 1];
  162.                     if (isGo(2)) {
  163.                         gTable.myTable[x + 2][y] = 0;
  164.                         gTable.myTable[x + 1][y + 1] = 0;
  165.                         gTable.myTable[x - 1][y] = 1;
  166.                         gTable.myTable[x][y + 1] = 1;
  167.                         x -= 1;
  168.                         return true;
  169.                     }
  170.                     else {
  171.                         return false;
  172.                     }
  173.                 }
  174.                 else {
  175.                     return false;
  176.                 }
  177.             case 4:
  178.                 if (x >= 1) {
  179.                     store[0] = gTable.myTable[x][y];
  180.                     store[1] = gTable.myTable[x - 1][y + 1];
  181.                     store[2] = gTable.myTable[x][y + 2];
  182.                     if (isGo(3)) {
  183.                         gTable.myTable[x + 1][y] = 0;
  184.                         gTable.myTable[x + 1][y + 1] = 0;
  185.                         gTable.myTable[x + 1][y + 2] = 0;
  186.                         gTable.myTable[x][y] = 1;
  187.                         gTable.myTable[x - 1][y + 1] = 1;
  188.                         gTable.myTable[x][y + 2] = 1;
  189.                         x -= 1;
  190.                         return true;
  191.                     }
  192.                     else {
  193.                         return false;
  194.                     }
  195.                 }
  196.                 else {
  197.                     return false;
  198.                 }
  199.             default:
  200.                 return false;
  201.         }
  202.     }
  203.     public boolean right() {
  204.         switch (direct) {
  205.             case 1:
  206.                 if (x <= gTable.x - 4) {
  207.                     store[0] = gTable.myTable[x + 2][y];
  208.                     store[1] = gTable.myTable[x + 3][y + 1];
  209.                     if (isGo(2)) {
  210.                         gTable.myTable[x + 1][y] = 0;
  211.                         gTable.myTable[x][y + 1] = 0;
  212.                         gTable.myTable[x + 2][y] = 1;
  213.                         gTable.myTable[x + 3][y + 1] = 1;
  214.                         x += 1;
  215.                         return true;
  216.                     }
  217.                     else {
  218.                         return false;
  219.                     }
  220.                 }
  221.                 else {
  222.                     return false;
  223.                 }
  224.             case 2:
  225.                 if (x <= gTable.x - 3) {
  226.                     store[0] = gTable.myTable[x + 1][y];
  227.                     store[1] = gTable.myTable[x + 2][y + 1];
  228.                     store[2] = gTable.myTable[x + 1][y + 2];
  229.                     if (isGo(3)) {
  230.                         gTable.myTable[x][y] = 0;
  231.                         gTable.myTable[x][y + 1] = 0;
  232.                         gTable.myTable[x][y + 2] = 0;
  233.                         gTable.myTable[x + 1][y] = 1;
  234.                         gTable.myTable[x + 2][y + 1] = 1;
  235.                         gTable.myTable[x + 1][y + 2] = 1;
  236.                         x += 1;
  237.                         return true;
  238.                     }
  239.                     else {
  240.                         return false;
  241.                     }
  242.                 }
  243.                 else {
  244.                     return false;
  245.                 }
  246.             case 3:
  247.                 if (x <= gTable.x - 4) {
  248.                     store[0] = gTable.myTable[x + 3][y];
  249.                     store[1] = gTable.myTable[x + 2][y + 1];
  250.                     if (isGo(2)) {
  251.                         gTable.myTable[x][y] = 0;
  252.                         gTable.myTable[x + 1][y + 1] = 0;
  253.                         gTable.myTable[x + 3][y] = 1;
  254.                         gTable.myTable[x + 2][y + 1] = 1;
  255.                         x += 1;
  256.                         return true;
  257.                     }
  258.                     else {
  259.                         return false;
  260.                     }
  261.                 }
  262.                 else {
  263.                     return false;
  264.                 }
  265.             case 4:
  266.                 if (x <= gTable.x - 3) {
  267.                     store[0] = gTable.myTable[x + 2][y];
  268.                     store[1] = gTable.myTable[x + 2][y + 1];
  269.                     store[2] = gTable.myTable[x + 2][y + 2];
  270.                     if (isGo(3)) {
  271.                         gTable.myTable[x][y + 1] = 0;
  272.                         gTable.myTable[x + 1][y] = 0;
  273.                         gTable.myTable[x + 1][y + 2] = 0;
  274.                         gTable.myTable[x + 2][y] = 1;
  275.                         gTable.myTable[x + 2][y + 1] = 1;
  276.                         gTable.myTable[x + 2][y + 2] = 1;
  277.                         x += 1;
  278.                         return true;
  279.                     }
  280.                     else {
  281.                         return false;
  282.                     }
  283.                 }
  284.                 else {
  285.                     return false;
  286.                 }
  287.             default:
  288.                 return false;
  289.         }
  290.     }
  291.     public boolean change() {
  292.         switch (direct) {
  293.             case 1:
  294.                 if (true) {
  295.                     store[0] = gTable.myTable[x][y];
  296.                     store[1] = gTable.myTable[x][y - 1];
  297.                     store[2] = gTable.myTable[x + 1][y - 1];
  298.                     if (isGo(3)) {
  299.                         gTable.myTable[x + 1][y + 1] = 0;
  300.                         gTable.myTable[x + 2][y + 1] = 0;
  301.                         gTable.myTable[x][y] = 1;
  302.                         gTable.myTable[x][y - 1] = 1;
  303.                         y -= 1;
  304.                         direct = 2;
  305.                         return true;
  306.                     }
  307.                     else {
  308.                         return false;
  309.                     }
  310.                 }
  311.                 else {
  312.                     return false;
  313.                 }
  314.             case 2:
  315.                 if (x <= gTable.x - 3) {
  316.                     store[0] = gTable.myTable[x + 1][y];
  317.                     store[1] = gTable.myTable[x + 2][y];
  318.                     store[2] = gTable.myTable[x + 2][y + 1];
  319.                     store[3] = gTable.myTable[x + 1][y + 2];
  320.                     if (isGo(4)) {
  321.                         gTable.myTable[x][y] = 0;
  322.                         gTable.myTable[x][y + 2] = 0;
  323.                         gTable.myTable[x + 2][y + 1] = 1;
  324.                         gTable.myTable[x + 1][y + 2] = 1;
  325.                         y += 1;
  326.                         direct = 3;
  327.                         return true;
  328.                     }
  329.                     else {
  330.                         return false;
  331.                     }
  332.                 }
  333.                 else {
  334.                     return false;
  335.                 }
  336.             case 3:
  337.                 if (true) {
  338.                     store[0] = gTable.myTable[x][y - 1];
  339.                     store[1] = gTable.myTable[x + 1][y - 1];
  340.                     store[2] = gTable.myTable[x + 2][y - 1];
  341.                     store[3] = gTable.myTable[x + 2][y + 1];
  342.                     if (isGo(4)) {
  343.                         gTable.myTable[x][y] = 0;
  344.                         gTable.myTable[x + 1][y + 1] = 0;
  345.                         gTable.myTable[x + 2][y - 1] = 1;
  346.                         gTable.myTable[x + 2][y + 1] = 1;
  347.                         x += 1;
  348.                         y -= 1;
  349.                         direct = 4;
  350.                         return true;
  351.                     }
  352.                     else {
  353.                         return false;
  354.                     }
  355.                 }
  356.                 else {
  357.                     return false;
  358.                 }
  359.             case 4:
  360.                 if (x <= gTable.x - 3) {
  361.                     store[0] = gTable.myTable[x + 2][y];
  362.                     store[1] = gTable.myTable[x + 2][y + 1];
  363.                     store[2] = gTable.myTable[x + 2][y + 2];
  364.                     store[3] = gTable.myTable[x][y + 2];
  365.                     if (isGo(4)) {
  366.                         gTable.myTable[x + 1][y] = 0;
  367.                         gTable.myTable[x][y + 1] = 0;
  368.                         gTable.myTable[x][y + 2] = 1;
  369.                         gTable.myTable[x + 2][y + 2] = 1;
  370.                         y += 1;
  371.                         direct = 1;
  372.                         return true;
  373.                     }
  374.                     else {
  375.                         return false;
  376.                     }
  377.                 }
  378.                 else {
  379.                     return false;
  380.                 }
  381.             default:
  382.                 return false;
  383.         }
  384.     }
  385.     public void downTo() {
  386.         boolean canDown = true;
  387.         while (canDown) {
  388.             canDown = down();
  389.         }
  390.     }
  391.     public boolean isGo(int n) {
  392.         for (int i = 0; i <= (n - 1); i++) {
  393.             if (store[i] != 0)
  394.                 return false;
  395.         }
  396.         return true;
  397.     }
  398.     public static void main(String args[]) {
  399.         new Seven();
  400.     }
  401. }