Exemplo n.º 1
0
 public Wall(int x, int y, ConsoleColor color)
 {
     for (int i = 0; i < wall.Length; i++)
     {
         wall[i] = new Obstacles(x, y + i, color);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates 4 arrays of obstacles: Top, Bottom, Left, and Right.
        /// Each Wall has an array of Obstacles that have an X,Y position and size.
        /// After each wall is checked for collision then it fills the wall into
        /// the allWalls list to print.
        /// </summary>
        public void createWalls(int size)
        {
            //TODO find a better way to go through this.

            int topWallSize    = rand.Next((int)(Math.Round(gridYHeight * .20)), (int)(Math.Round(gridYHeight * .70)));
            int bottomWallSize = rand.Next((int)(Math.Round(gridYHeight * .20)), (int)(Math.Round(gridYHeight * .70)));
            int leftWallSize   = rand.Next((int)(Math.Round(gridXLength * .20)), (int)Math.Round(gridXLength * .70));
            int rightWallSize  = rand.Next((int)(Math.Round(gridXLength * .20)), (int)Math.Round(gridXLength * .70));
            int randWallX      = rand.Next((leftMargin + 5), ((leftMargin + gridXLength) - 5));
            int randWallY      = rand.Next((topMargin + 5), ((topMargin + gridYHeight) - 5));

            topWall = new Obstacles[topWallSize];
            for (int i = 0; i < topWallSize; i++)
            {
                topWall[i] = new Obstacles(randWallX, randWallX + 1, (topMargin + 1) + i, ConsoleColor.Gray);
            }
            allWalls.Add(topWall);

            bottomWall = new Obstacles[bottomWallSize];
            randWallX  = rand.Next((leftMargin + 5), ((leftMargin + gridXLength) - 5));
            for (int i = 0; i < bottomWallSize; i++)
            {
                if (collisions.checkWall(allWalls, randWallX, ((topMargin - 2) + gridYHeight) - i))
                {
                    while (collisions.checkWall(allWalls, randWallX, ((topMargin - 2) + gridYHeight) - i))
                    {
                        randWallX = rand.Next((leftMargin + 5), ((leftMargin + gridXLength) - 5));
                        i         = 0;
                    }
                }
                bottomWall[i] = new Obstacles(randWallX, randWallX + 1, ((topMargin - 2) + gridYHeight) - i, ConsoleColor.Gray);
            }
            allWalls.Add(bottomWall);

            rightWall = new Obstacles[rightWallSize];
            for (int i = 0; i < rightWallSize; i++)
            {
                if (collisions.checkWall(allWalls, (leftMargin + gridXLength) - i, randWallY))
                {
                    while (collisions.checkWall(allWalls, (leftMargin + gridXLength) - i, randWallY))
                    {
                        randWallY = rand.Next((topMargin + 5), ((topMargin + gridYHeight) - 5));
                        i         = 0;
                    }
                }

                rightWall[i] = new Obstacles((leftMargin + gridXLength) - i, ((leftMargin + gridXLength) - i), randWallY, ConsoleColor.Gray);
            }
            allWalls.Add(rightWall);

            leftWall  = new Obstacles[leftWallSize];
            randWallY = rand.Next((topMargin + 5), ((topMargin + gridYHeight) - 5));
            for (int i = 0; i < leftWallSize; i++)
            {
                if (collisions.checkWall(allWalls, (leftMargin + 1) + i, randWallY))
                {
                    while (collisions.checkWall(allWalls, (leftMargin + 1) + i, randWallY))
                    {
                        randWallY = rand.Next((topMargin + 5), ((topMargin + gridYHeight) - 5));
                        i         = 0;
                    }
                }

                leftWall[i] = new Obstacles((leftMargin + 1) + i, (leftMargin + 1) + i, randWallY, ConsoleColor.Gray);
            }
            allWalls.Add(leftWall);
        }