Example #1
0
        public void CheckFatherPanelForPath()
        {
            if (Father.HasEndPoint && Father.HasStartPoint)
            {
                ResetFatherScene();

                if (Father.UseDFS)
                {
                    Father.CreatePathUsingDFS(Father.MazeStartPoint);
                }
                else
                {
                    Father.CreatePathUsingBFS(Father.MazeStartPoint);
                }

                var temp     = Father.MazeEndPoint;
                var tempPrev = Father.MazeEndPoint.Previous;

                while (tempPrev != null && tempPrev != Father.MazeStartPoint)
                {
                    tempPrev.Next = temp;
                    // Use green-background only for bfs
                    if (!Father.UseDFS)
                    {
                        tempPrev.Background = new RadialGradientBrush(
                            (Color)ColorConverter.ConvertFromString("#FF8BFF84"),
                            (Color)ColorConverter.ConvertFromString("#FF7AE573")
                            );
                    }

                    int tempIndex = Father.ButtonsList.IndexOf(tempPrev);
                    int prevIndex = Father.ButtonsList.IndexOf(tempPrev.Previous);
                    int nextIndex = Father.ButtonsList.IndexOf(tempPrev.Next);

                    // Graphical Paths for DFS and BFS
                    if (Father.UseDFS)
                    {
                        if (prevIndex == Father.GetNorth(tempIndex))
                        {
                            if (nextIndex == Father.GetSouth(tempIndex))
                            {
                                tempPrev.Content = new Vertical();
                            }

                            else if (nextIndex == Father.GetEast(tempIndex))
                            {
                                tempPrev.Content = new LeftToUp();
                            }

                            else if (nextIndex == Father.GetWest(tempIndex))
                            {
                                tempPrev.Content = new UpToRight();
                            }
                        }

                        else if (prevIndex == Father.GetSouth(tempIndex))
                        {
                            if (nextIndex == Father.GetNorth(tempIndex))
                            {
                                tempPrev.Content = new Vertical();
                            }

                            else if (nextIndex == Father.GetEast(tempIndex))
                            {
                                tempPrev.Content = new LeftToDown();
                            }

                            else if (nextIndex == Father.GetWest(tempIndex))
                            {
                                tempPrev.Content = new RightToDown();
                            }
                        }

                        else if (prevIndex == Father.GetEast(tempIndex))
                        {
                            if (nextIndex == Father.GetSouth(tempIndex))
                            {
                                tempPrev.Content = new LeftToDown();
                            }

                            else if (nextIndex == Father.GetNorth(tempIndex))
                            {
                                tempPrev.Content = new LeftToUp();
                            }

                            else if (nextIndex == Father.GetWest(tempIndex))
                            {
                                tempPrev.Content = new Horizontal();
                            }
                        }

                        else if (prevIndex == Father.GetWest(tempIndex))
                        {
                            if (nextIndex == Father.GetSouth(tempIndex))
                            {
                                tempPrev.Content = new RightToDown();
                            }

                            else if (nextIndex == Father.GetNorth(tempIndex))
                            {
                                tempPrev.Content = new UpToRight();
                            }

                            else if (nextIndex == Father.GetEast(tempIndex))
                            {
                                tempPrev.Content = new Horizontal();
                            }
                        }
                    }
                    else
                    {
                        if (prevIndex == Father.GetNorth(tempIndex))
                        {
                            tempPrev.Content = new Up();
                        }
                        else if (prevIndex == Father.GetSouth(tempIndex))
                        {
                            tempPrev.Content = new Down();
                        }
                        else if (prevIndex == Father.GetEast(tempIndex))
                        {
                            tempPrev.Content = new Right();
                        }
                        else if (prevIndex == Father.GetWest(tempIndex))
                        {
                            tempPrev.Content = new Left();
                        }
                    }

                    temp     = temp.Previous;
                    tempPrev = tempPrev.Previous;
                }
            }
        }