예제 #1
0
파일: Player.cs 프로젝트: Silby17/Ex1_Maze
        /// <summary>
        /// Method that will make the necessary move according
        /// to the users input</summary>
        /// <param name="direction">Direction of the move</param>
        public void Move(string direction)
        {
            switch (direction.ToLower())
            {
            case "up":
                playerMaze.SetCell(currentNode.GetRow() - 1,
                                   currentNode.GetCol(), 3);
                this.currentNode = playerMaze.GetNode(
                    currentNode.GetRow() - 1, currentNode.GetCol());
                break;

            case "right":
                playerMaze.SetCell(currentNode.GetRow(),
                                   currentNode.GetCol() + 1, 3);
                this.currentNode = playerMaze.GetNode(
                    currentNode.GetRow(), currentNode.GetCol() + 1);
                break;

            case "down":
                playerMaze.SetCell(currentNode.GetRow() + 1,
                                   currentNode.GetCol(), 3);
                this.currentNode = playerMaze.GetNode(
                    currentNode.GetRow() + 1, currentNode.GetCol());
                break;

            case "left":
                playerMaze.SetCell(currentNode.GetRow(),
                                   currentNode.GetCol() - 1, 3);
                this.currentNode = playerMaze.GetNode(
                    currentNode.GetRow(), currentNode.GetCol() - 1);
                break;
            }
        }
예제 #2
0
        /// <summary>
        /// This will get all the neighbours of a certain Node</summary>
        /// <param name="neighbors">Returns the list of neighbours</param>
        /// <returns></returns>
        public List <Node <T> > getNeighbors(List <Node <T> > neighbors)
        {
            int rundomNumber = new Random().Next(neighbors.Count);
            //choose a randon neighbor to go to
            Node <T> current = neighbors[rundomNumber];

            maze.SetCell(current.GetRow(), current.GetCol(), 0);

            //check if ther are parents to mark the point between
            if (current.GetParent() != null)
            {
                int colBetwen = (current.GetParent().GetCol() + current.GetCol()) / 2;
                int rowBetwen = (current.GetParent().GetRow() + current.GetRow()) / 2;
                if (colBetwen < 0)
                {
                    colBetwen *= -1;
                }
                if (rowBetwen < 0)
                {
                    rowBetwen *= -1;
                }
                this.maze.SetCell(rowBetwen, colBetwen, 0);
            }


            //Removes the current Node from the List
            neighbors.Remove(current);
            this.last = current;
            //Saves the indecies of the current node
            int col = current.GetCol();
            int row = current.GetRow();

            //Checks Up
            if (row - 2 >= 0 && this.maze.GetValue(row - 1, col) == 1 &&
                this.maze.GetValue(row - 2, col) == 1)
            {
                neighbors.Add(new Node <T>(row - 2, col, current));
            }
            //Checks Down
            if (row + 2 < this.height && this.maze.GetValue(row + 1, col) == 1 &&
                this.maze.GetValue(row + 2, col) == 1)
            {
                neighbors.Add(new Node <T>(row + 2, col, current));
            }
            //Checks Left
            if (col - 2 >= 0 && this.maze.GetValue(row, col - 1) == 1 &&
                this.maze.GetValue(row, col - 2) == 1)
            {
                neighbors.Add(new Node <T>(row, col - 1, current));
            }
            //Checks Right
            if (col + 2 < this.width && this.maze.GetValue(row, col + 1) == 1 &&
                this.maze.GetValue(row, col + 2) == 1)
            {
                neighbors.Add(new Node <T>(row, col + 2, current));
            }
            return(neighbors);
        }
예제 #3
0
        /// <summary>
        /// THis method will sent a random starting point
        /// in the maze and set it to 0
        /// </summary>
        public void RandomStart()
        {
            Random rand = new Random();
            int    row  = rand.Next(0, HEIGHT);
            int    col  = rand.Next(0, WIDTH);

            maze.SetCell(row, col, 0);
            maze.SetStartPoints(row, col);

            //This will start createing the maze using recursion
            Recursion(row, col);

            //This will set the end points of the maze
            maze.SetEndPoints(endRow, endCol);
        }