nodezlevel.java

来自「java learn PPT java learn PPT java learn」· Java 代码 · 共 146 行

JAVA
146
字号
     import java.awt.*;
     import java.awt.event.*;
     import java.awt.geom.*;
     import java.util.*;

     import magic.graphics.*;

     public abstract class NodezLevel extends Object
     {
          // 获取节点宽和高的快捷方式
          protected final int NW = NodeGroup.NODE_WIDTH;
          protected final int NH = NodeGroup.NODE_HEIGHT;

          // 节点的位置, 参考窗体的中心
          // 比如<100, -100>是窗体中心右100个单位上100个单位的位置
          protected Vector2D[] nodePos;

          // 索引匹配圈; 索引0所在的项和索引1所在的项相连
          protected int[][]    circuits;

          // 获取节点位置
          public abstract Vector2D[] getNodePos();

          // 获取线圈索引
          public abstract int[][]    getCircuits();

          // 当前选择的级别
          public static int MAX_LEVELS = 3;

          // 根据传入的级别数,返回一个新的NodezLevel对象.
          public static NodezLevel getLevel(int n)
          {
               switch(n)
               {
                    case 1:
                         return new NodezLevel1();   

                    case 2:
                         return new NodezLevel2();  

                    case 3:
                         return new NodezLevel3();

                    default:
                         return null;
              }
          }

          // 代表级别1的类
          static class NodezLevel1 extends NodezLevel
          {
               public Vector2D[] getNodePos()
               {
                    Vector2D[] v = { 
                          new Vector2D.Double(),
                          new Vector2D.Double(-NW/2,    -100),      new Vector2D.Double(NW/2,   -100),
                          new Vector2D.Double(-100-NW/4, 100+NW/4), new Vector2D.Double(-104-NW, 100-NW/4),
                          new Vector2D.Double( 100+NW/4, 100+NW/4), new Vector2D.Double( 104+NW, 100-NW/4) 
                          };

                    nodePos = v;
                    return nodePos;
               }

               public int[][] getCircuits()
               {
                    int[][] c = { {0, 3}, {0, 5},
                                  {1, 2}, {1, 4},
                                  {2, 6},
                                  {3, 4}, {3, 5},
                                  {5, 6}
                                  };
         
                    circuits = c;
                    return circuits;
               }
          }

          // 代表级别2的类
          static class NodezLevel2 extends NodezLevel
          {
               public Vector2D[] getNodePos()
               {
                    Vector2D[] v = { 
                          new Vector2D.Double(   0,   NH), new Vector2D.Double(  75,  125),
                          new Vector2D.Double(   0,  -NH), new Vector2D.Double( -75,  125),
                          new Vector2D.Double(   0,  150), new Vector2D.Double( 150,   75),
                          new Vector2D.Double( 150,  -75), new Vector2D.Double(   0, -150),
                          new Vector2D.Double(-150,  -75), new Vector2D.Double(-150,   75),
                          };

                    nodePos = v;
                    return nodePos;
               }

               public int[][] getCircuits()
               {
                    int[][] c = { {0, 2}, {0, 9},
                                  {1, 4}, 
                                  {2, 6},
                                  {3, 4},
                                  {4, 6}, {4, 8},
                                  {5, 7},
                                  {7, 9} 
                                  };
         
                    circuits = c;
                    return circuits;
               }
          }          

          // 代表级别3的类
          static class NodezLevel3 extends NodezLevel
          {
               public Vector2D[] getNodePos()
               {
                    Vector2D[] v = { 
                          new Vector2D.Double(-175,  100), new Vector2D.Double(-165, -100),
                          new Vector2D.Double( -85,    0), new Vector2D.Double( -25,  100),
                          new Vector2D.Double( -50, -100), new Vector2D.Double(  75,  100),
                          new Vector2D.Double(  65, -100), new Vector2D.Double(  75,    0),
                          new Vector2D.Double( 175,  100), new Vector2D.Double( 170, -100),
                          };

                    nodePos = v;
                    return nodePos;
               }

               public int[][] getCircuits()
               {
                    int[][] c = { {0, 1},
                                  {1, 2},
                                  {2, 4},
                                  {3, 4}, {3, 6},
                                  {4, 5},
                                  {5, 7}, {5, 8},
                                  {6, 7},
                                  {7, 9} 
                                  };
         
                    circuits = c;
                    return circuits;
               }
          }          

     }    // NodezLevel

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?