예제 #1
0
        public Square squareB; // Door connected square with higher Room ID

        #endregion Fields

        #region Constructors

        public Door(Square a, Square b)
        {
            squareA = a;
            squareB = b;
        }
예제 #2
0
        private void setUpSquares()
        {
            // Initialize all the squares
            Console.Write("Initializing squares... ");
            int squareCntr = 0;
            for (int y = 0; y < board.gridY; y++)
            {
                for (int x = 0; x < board.gridX; x++)
                {
                    Square tempSquare = new Square();
                    tempSquare.squareID = squareCntr;
                    tempSquare.X = x;
                    tempSquare.Y = y;
                    tempSquare.roomID = 0;
                    tempSquare.blockType = (int)BlockType.Unset;
                    tempSquare.adjSquares = new List<Square>();
                    tempSquare.connSquares = new List<Square>();

                    board.grid.Add(tempSquare);

                    squareCntr++;
                }
            }
            Console.WriteLine("Complete");

            // Connect adjacent squares to each other
            Console.Write("Connecting adjacent squares... ");
            foreach (Square crntSquare in board.grid)
            {
                // Connect the square to the left
                if (crntSquare.X - 1 >= 0)
                {
                    Square adjSquare = board.grid.First<Square>(
                        delegate(Square tempSquare)
                        {
                            return(tempSquare.X == (crntSquare.X - 1)
                                && tempSquare.Y == crntSquare.Y);
                        }
                    );
                    crntSquare.adjSquares.Add(adjSquare);
                }

                // Connect the square to the top
                if (crntSquare.Y - 1 >= 0)
                {
                    Square adjSquare = board.grid.First<Square>(
                        delegate(Square tempSquare)
                        {
                            return(tempSquare.X == crntSquare.X
                                && tempSquare.Y == (crntSquare.Y - 1));
                        }
                    );
                    crntSquare.adjSquares.Add(adjSquare);
                }

                // Connect the square to the right
                if (crntSquare.X + 1 < board.gridX)
                {
                    Square adjSquare = board.grid.First<Square>(
                        delegate(Square tempSquare)
                        {
                            return (tempSquare.X == (crntSquare.X + 1)
                                && tempSquare.Y == crntSquare.Y);
                        }
                    );
                    crntSquare.adjSquares.Add(adjSquare);
                }

                // Connect the square to the bottom
                if (crntSquare.Y + 1 < board.gridY)
                {
                    Square adjSquare = board.grid.First<Square>(
                        delegate(Square tempSquare)
                        {
                            return (tempSquare.X == crntSquare.X
                                && tempSquare.Y == (crntSquare.Y + 1));
                        }
                    );
                    crntSquare.adjSquares.Add(adjSquare);
                }
            }
            Console.WriteLine("Complete");
        }