コード例 #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>
        /// Main Method that will created a maze using Prims Algorithm </summary>
        /// <param name="createable">Maze</param>
        public void create(ICreateable <T> createable)
        {
            this.maze   = createable.GetMaze();
            this.height = createable.GetHeight();
            this.width  = createable.GetWidth();
            List <Node <T> > primList = new List <Node <T> >();

            rand = new Random();

            //Sets a random Starting Point
            int rRow = rand.Next(height);
            int rCol = rand.Next(width);

            maze.GetNode(rRow, rCol).SetValue(0);
            maze.SetStartPoints(rRow, rCol);

            //Adds Node to the Prims List
            primList.Add(maze.GetNode(rRow, rCol));

            //Will run as long as the List is not empty
            while (primList.Count > 0)
            {
                primList = primList.Distinct().ToList();
                this.getNeighbors(primList);
            }
            //Sets the end Point of the maze
            this.maze.SetEndPoints(last.GetRow(), last.GetCol());
        }