예제 #1
0
        public PipeNode ConnectPipeRecursive(PipeNode target, List <PipeNode> path, int index)
        {
            PipeNode node = null;

            if (this.Equals(target))
            {
                Connecting = true;
                try
                {
                    System.Threading.Thread.Sleep(60);
                }
                catch (ThreadInterruptedException exception) { }
                return(target);
            }
            else
            {
                if (index < path.Count - 1 && path[index + 1] != null)
                {
                    Connecting = true;
                    try
                    {
                        System.Threading.Thread.Sleep(60);
                    }
                    catch (ThreadInterruptedException exception) { }
                    index++;
                    path[index].ConnectPipeRecursive(target, path, index);
                }
            }
            return(node);
        }
예제 #2
0
        public List <PipeNode> GetPath(PipeNode target)
        {
            if (Globals.UltraDebug)
            {
                Printer.Info($"Getting path for {target.Print()}");
            }
            List <PipeNode> path = new List <PipeNode>();

            path = GetPathRecursive(target, path);
            return(path);
        }
예제 #3
0
        public bool CanConnectedWith(PipeNode target)
        {
            bool            connected = false;
            List <PipeNode> path      = GetPath(target);

            if (path.Count > 0 && path.Last().Equals(target))
            {
                connected = true;
            }
            return(connected);
        }
예제 #4
0
        public List <PipeNode> GetPathRecursive(PipeNode target, List <PipeNode> path)
        {
            //if (Globals.UltraDebug) { Printer.Info(Print()); }
            Node adj;

            if (path.Contains(target))
            {
                return(path);
            }
            else
            {
                path.Add(this);
                adj = Adjacents[Sides.North];
                if (!path.Contains(target) && adj != null && adj is PipeNode && !path.Contains(adj))
                {
                    PipeNode adjPipe = (PipeNode)adj;
                    path = adjPipe.GetPathRecursive(target, path);
                }
                adj = Adjacents[Sides.South];
                if (!path.Contains(target) && adj != null && adj is PipeNode && !path.Contains(adj))
                {
                    PipeNode adjPipe = (PipeNode)adj;
                    path = adjPipe.GetPathRecursive(target, path);
                }
                adj = Adjacents[Sides.East];
                if (!path.Contains(target) && adj != null && adj is PipeNode && !path.Contains(adj))
                {
                    PipeNode adjPipe = (PipeNode)adj;
                    path = adjPipe.GetPathRecursive(target, path);
                }
                adj = Adjacents[Sides.West];
                if (!path.Contains(target) && adj != null && adj is PipeNode && !path.Contains(adj))
                {
                    PipeNode adjPipe = (PipeNode)adj;
                    path = adjPipe.GetPathRecursive(target, path);
                }
                if (!path.Contains(target))
                {
                    path.Remove(this);
                }
                return(path);
            }
        }
예제 #5
0
        public void ConnectPipe(PipeNode target)
        {
            List <PipeNode> path = GetPath(target);

            /*
             * Printer.Info($"[T{Thread.CurrentThread.ManagedThreadId}] PATH---------------");
             * foreach (Node node in path)
             * {
             *  Printer.Info(node.Print());
             * }
             * Printer.Info($"[T{Thread.CurrentThread.ManagedThreadId}] PATH---------------");
             */
            ConnectPipeRecursive(target, path, 0);
            foreach (PipeNode pipe in path)
            {
                pipe.Connecting = false;
                try
                {
                    System.Threading.Thread.Sleep(20);
                }
                catch (ThreadInterruptedException exception) { }
            }
        }