コード例 #1
0
 public MazeCell(Map map, MazeCell parent)
 {
     splitOrientation = SplitOrientation.None;
     this.map         = map;
     this.parent      = parent;
 }
コード例 #2
0
 void split()
 {
     splitOrientation = chooseSplit();
     if (splitOrientation == SplitOrientation.Horizontal)
     {
         int r = Rng.Random.Next(width - 2) + 1;
         child1    = new MazeCell(map, this);
         child1.x1 = x1;
         child1.y1 = y1;
         child1.x2 = x1 + r - 1;
         child1.y2 = y2;
         child2    = new MazeCell(map, this);
         child2.x1 = x1 + r + 1;
         child2.y1 = y1;
         child2.x2 = x2;
         child2.y2 = y2;
         for (int y = y1; y <= y2; ++y)
         {
             map[x1 + r, y] = Terrain.Get("wall").Character;
         }
         if (parent == null || splitOrientation == parent.splitOrientation)
         {
         }
         else
         {
             connection = Rng.Random.Next(height - 1);
             if (connection >= parent.connection)
             {
                 connection++;
             }
         }
         connection = Rng.Random.Next(height);
         map[x1 + r, y1 + connection] = Terrain.Get("ground").Character;
     }
     if (splitOrientation == SplitOrientation.Vertical)
     {
         int r = Rng.Random.Next(height - 2) + 1;
         child1    = new MazeCell(map, this);
         child1.x1 = x1;
         child1.y1 = y1;
         child1.x2 = x2;
         child1.y2 = y1 + r - 1;
         child2    = new MazeCell(map, this);
         child2.x1 = x1;
         child2.y1 = y1 + r + 1;
         child2.x2 = x2;
         child2.y2 = y2;
         for (int x = x1; x <= x2; ++x)
         {
             map[x, y1 + r] = Terrain.Get("wall").Character;
         }
         connection = Rng.Random.Next(width);
         map[x1 + connection, y1 + r] = Terrain.Get("ground").Character;
     }
     if (child1.canSplit)
     {
         child1.split();
     }
     if (child2.canSplit)
     {
         child2.split();
     }
 }