Пример #1
0
        private void DiscernPath(DiscernPathResult result, MazeNode parent, MazeNode node, MazeNode.Direction direction, int ability, int deep)
        {
            result.Rectangle = result.Rectangle.Union(new Rectangle(node.X, node.Y, 1, 1));
            result.Paths.Add(node);
            foreach (MazeNode next in node.GetEnumeratorExclude(parent))
            {
                int ability2 = ability;
                MazeNode.Direction direction2 = next.ToNodeDirection(node);
                if (direction != direction2)                     // 非直线
                {
                    if (next.IsOnlyOnePath(direction2))          // 无分支
                    {
                        ability2++;
                    }
                    else
                    {
                        ability2 += deep;
                    }
                }
                else
                {
                    if (!next.IsOnlyOnePath(direction2))
                    {
                        ability2++;
                    }
                }

                if (ability2 <= DiscernPathAbility)
                {
                    DiscernPath(result, node, next, direction2, ability2, deep + 1);
                }
            }
        }
Пример #2
0
        public bool Goto(MazeNode.Direction from)
        {
            List <Point> eventArgs = null;

            if (this.Changed != null)
            {
                eventArgs = new List <Point>()
                {
                    new Point(userX, userY)
                }
            }
            ;

            MazeNode temp = GotoNode(map[userX, userY], from);

            if (temp != null)
            {
                userX = temp.X;
                userY = temp.Y;
            }
            else
            {
                return(false);
            }

            MazeNode next;

            do
            {
                next = map[userX, userY];
                if (userPath.Count >= 2 && userPath[userPath.Count - 2] == next)
                {
                    userPath.RemoveAt(userPath.Count - 1);
                }
                else
                {
                    userPath.Add(next);
                }

                if (userX == EndX && userY == EndY && this.Completed != null)
                {
                    this.Completed();
                }

                if (this.Changed != null)
                {
                    eventArgs.Add(new Point(userX, userY));
                }
            } while (IsFindBranch && next.OnlyOnePath(ref userX, ref userY, ref from));

            userChanged = true;
            result      = DiscernPath();
            if (this.Changed != null)
            {
                this.Changed(new MazeEventArgs(eventArgs));
            }
            return(true);
        }
Пример #3
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.Modifiers == Keys.None)
            {
                //Rectangle pathRectangle;
                MazeNode.Direction direction = MazeNode.Direction.None;
                switch (e.KeyCode)
                {
                case Keys.Left: direction = MazeNode.Direction.Right; break;

                case Keys.Right: direction = MazeNode.Direction.Left; break;

                case Keys.Up: direction = MazeNode.Direction.Down; break;

                case Keys.Down: direction = MazeNode.Direction.Up; break;

                case Keys.Back:
                    map.Back();
                    StartScroll();
                    this.Invalidate();
                    goto Result;

                default: goto Result;
                }

                map.WiseGoto(direction);
                StartScroll();
                this.Invalidate();
            }
            else if (e.Control)
            {
                int weight = map.Weight;
                switch (e.KeyCode)
                {
                case Keys.Up: map.Weight++; break;

                case Keys.Down: map.Weight--; break;

                default: goto Result;
                }

                if (map.Weight <= 0)
                {
                    map.Weight = 1;
                }

                offset.X = map.UserX * map.Weight + offset.X + (-map.UserX * map.Weight) * map.Weight / weight;
                offset.Y = map.UserY * map.Weight + offset.Y + (-map.UserY * map.Weight) * map.Weight / weight;

                this.AdjustSize();
                this.Redress();
                this.Invalidate();
            }

Result:
            base.OnKeyDown(e);
        }
Пример #4
0
        private MazeNode GotoNode(MazeNode node, MazeNode.Direction from)
        {
            switch (from)
            {
            case MazeNode.Direction.Left: return(node.Right ? map[node.X + 1, node.Y] : null);

            case MazeNode.Direction.Right: return(node.Left ? map[node.X - 1, node.Y] : null);

            case MazeNode.Direction.Up: return(node.Down ? map[node.X, node.Y + 1] : null);

            case MazeNode.Direction.Down: return(node.Up ? map[node.X, node.Y - 1] : null);

            default: return(null);
            }
        }
Пример #5
0
 public bool WiseGoto(MazeNode.Direction from)
 {
     if (Goto(from))
     {
         return(true);
     }
     else
     {
         MazeNode           user       = map[userX, userY];
         MazeNode.Direction direction1 = from.ROL(1);
         MazeNode.Direction direction2 = from.ROL(3);
         MazeNode           node1      = GotoNode(user, direction1);
         MazeNode           node2      = GotoNode(user, direction2);
         if (node1 != null)
         {
             if (node2 != null)
             {
                 MazeNode node3 = GotoNode(node1, from);
                 MazeNode node4 = GotoNode(node2, from);
                 if (node3 != null && node4 == null)
                 {
                     return(Goto(direction1));
                 }
                 if (node3 == null && node4 != null)
                 {
                     return(Goto(direction2));
                 }
                 return(false);
             }
             else
             {
                 return(Goto(direction1));
             }
         }
         else
         {
             if (node2 != null)
             {
                 return(Goto(direction2));
             }
             else
             {
                 return(false);
             }
         }
     }
 }
Пример #6
0
 public static MazeNode.Direction ROR(this MazeNode.Direction direction, int value)
 {
     return(direction.ROL(4 - value));
 }
Пример #7
0
        public static MazeNode.Direction ROL(this MazeNode.Direction direction, int value)
        {
            int temp = (int)direction << value;

            return((MazeNode.Direction)((temp >> 4) | temp & 0xF));
        }