Пример #1
0
        void MakeWall(Mass m, Direction4 d)
        {
            int newI = m.I, newJ = m.J;
            switch (d)
            {
                case Direction4.Up: newI = m.I - 1; break;
                case Direction4.Right: newJ = m.J + 1; break;
                case Direction4.Down: newI = m.I + 1; break;
                case Direction4.Left: newJ = m.J - 1; break;
            }

            maze[newI, newJ].MassState = State.Wall;
        }
Пример #2
0
        protected override List<Direction4> SurveyDirection(Mass m)
        {
            int i = m.I, j = m.J;
            List<Direction4> directions = new List<Direction4>();
            if (i > 1 && m.Label != maze[i - 2, j].Label)
                directions.Add(Direction4.Up);
            if (i < mazeHeight - 2 && m.Label != maze[i + 2, j].Label)
                directions.Add(Direction4.Down);
            if (j > 1 && m.Label != maze[i, j - 2].Label)
                directions.Add(Direction4.Left);
            if (j < mazeWidth - 2 && m.Label != maze[i, j + 2].Label)
                directions.Add(Direction4.Right);

            return directions;
        }
Пример #3
0
        protected override List<Direction4> SurveyDirection(Mass m)
        {
            int i = m.I, j = m.J;
            List<Direction4> directions = new List<Direction4>();
            if (i > 1 && (maze[i - 2, j].MassState == State.Empty || maze[i - 2, j].MassState == State.Wall))
                directions.Add(Direction4.Up);
            if (i < mazeHeight - 2 && (maze[i + 2, j].MassState == State.Empty || maze[i + 2, j].MassState == State.Wall))
                directions.Add(Direction4.Down);
            if (j > 1 && (maze[i, j - 2].MassState == State.Empty || maze[i, j - 2].MassState == State.Wall))
                directions.Add(Direction4.Left);
            if (j < mazeWidth - 2 && (maze[i, j + 2].MassState == State.Empty || maze[i, j + 2].MassState == State.Wall))
                directions.Add(Direction4.Right);

            return directions;
        }
Пример #4
0
        protected override List<Direction4> SurveyDirection(Mass m)
        {
            int i = m.I, j = m.J;
            List<Direction4> directions = new List<Direction4>();
            if (i == 2 && maze[i - 1, j].MassState == State.Empty)
                directions.Add(Direction4.Up);
            if (i < mazeHeight - 1 && maze[i + 1, j].MassState == State.Empty)
                directions.Add(Direction4.Down);
            if (j > 0 && maze[i, j - 1].MassState == State.Empty)
                directions.Add(Direction4.Left);
            if (j < mazeWidth - 1 && maze[i, j + 1].MassState == State.Empty)
                directions.Add(Direction4.Right);

            return directions;
        }
Пример #5
0
        Mass MakeNewRoad(Mass m, Direction4 d)
        {
            int i = m.I, j = m.J;
            int newI = i, newJ = j;
            switch (d)
            {
                case Direction4.Up: newI = i - 2; break;
                case Direction4.Right: newJ = j + 2; break;
                case Direction4.Down: newI = i + 2; break;
                case Direction4.Left: newJ = j - 2; break;
            }

            maze[newI, newJ].MassState = State.Empty;

            return maze[newI, newJ];
        }
Пример #6
0
        int BreakWall(Mass m, Direction4 d, Dictionary<int, List<Mass>> clustering)
        {
            int i = m.I, j = m.J;
            int newI = i, newJ = j;
            Mass newMass = null;
            switch (d)
            {
                case Direction4.Up: newI = i - 1; newMass = maze[i - 2, j]; break;
                case Direction4.Right: newJ = j + 1; newMass = maze[i, j + 2]; break;
                case Direction4.Down: newI = i + 1; newMass = maze[i + 2, j]; break;
                case Direction4.Left: newJ = j - 1; newMass = maze[i, j - 2]; break;
            }

            int minLabel = Math.Min(m.Label, newMass.Label),
                maxLabel = Math.Max(m.Label, newMass.Label);

            maze[newI, newJ].MassState = State.Empty;

            if (clustering.ContainsKey(maxLabel))
                clustering[maxLabel].ForEach(c => c.Label = minLabel);

            return maxLabel;
        }
Пример #7
0
        Mass MakeNewWall(Mass m, Direction4 direction)
        {
            int i = m.I, j = m.J;
            int newI = i, newJ = j;
            switch (direction)
            {
                case Direction4.Up: newI = i - 2; break;
                case Direction4.Right: newJ = j + 2; break;
                case Direction4.Down: newI = i + 2; break;
                case Direction4.Left: newJ = j - 2; break;
            }

            if (maze[newI, newJ].MassState != State.Wall)
                maze[newI, newJ].MassState = State.NewWall;

            return maze[newI, newJ];
        }