//Override the Equals method to check for end point node.
        public override bool Equals(object obj)
        {
            WalledMazeNode mazeNode = obj as WalledMazeNode;

            if (mazeNode == null)
            {
                return(false);
            }
            if (object.ReferenceEquals(mazeNode, this))
            {
                return(true);
            }
            return(mazeNode.ColPosition == this.ColPosition && mazeNode.RowPosition == this.RowPosition && mazeNode.State == this.State);
        }
Esempio n. 2
0
        /// <summary>
        /// Scans the image and stores information.
        /// </summary>
        private void InitializeMaze(string imagePath, string wallColor, string gapColor, string startColor, string finishColor)
        {
            Bitmap mazeImage = null;

            try
            {
                mazeImage = new Bitmap(imagePath);
            }
            catch (ArgumentException)
            {
                throw new ArgumentException("Unable to convert the file to bitmap.");
            }

            _maze   = new WalledMazeNode[mazeImage.Height, mazeImage.Width];
            _height = mazeImage.Height;
            _width  = mazeImage.Width;

            for (i = 0; i < _height; i++)
            {
                for (j = 0; j < _width; j++)
                {
                    Color color = mazeImage.GetPixel(j, i);

                    if (color.Name == wallColor)
                    {
                        _maze[i, j] = new WalledMazeNode(i, j)
                        {
                            State = WalledMazeNodeState.Blocked
                        };
                        continue;
                    }
                    else if (color.Name == startColor)
                    {
                        _maze[i, j] = new WalledMazeNode(i, j)
                        {
                            State = WalledMazeNodeState.Gap
                        };
                        if (_source == null)
                        {
                            _source = _maze[i, j];
                        }
                    }
                    else if (color.Name == finishColor)
                    {
                        _maze[i, j] = new WalledMazeNode(i, j)
                        {
                            State = WalledMazeNodeState.Gap
                        };
                        if (_destination == null)
                        {
                            _destination = _maze[i, j];
                        }
                    }
                    else if (color.Name == gapColor)
                    {
                        _maze[i, j] = new WalledMazeNode(i, j)
                        {
                            State = WalledMazeNodeState.Gap
                        };
                    }
                    else
                    {
                        //Invalid color.
                        throw new Exception(string.Format("Color {0} is an illegal color. Please use colors specified.", color.Name));
                    }
                }
            }
        }