Ejemplo n.º 1
0
        public void AddNeighbours(GameGrid grid, bool diagonals = true)
        {
            int i = GetI();
            int j = GetJ();

            if (i < grid.GetCols() - 1)
            {
                m_neighbours.Add(grid.GetTiles()[i + 1, j]);
            }

            if (i > 0)
            {
                m_neighbours.Add(grid.GetTiles()[i - 1, j]);
            }

            if (j < grid.GetRows() - 1)
            {
                m_neighbours.Add(grid.GetTiles()[i, j + 1]);
            }

            if (j > 0)
            {
                m_neighbours.Add(grid.GetTiles()[i, j - 1]);
            }

            //Diagonals
            if (diagonals)
            {
                if ((i > 0) && (j > 0))
                {
                    m_neighbours.Add(grid.GetTiles()[i - 1, j - 1]);
                }

                if ((i < grid.GetCols() - 1) && (j > 0))
                {
                    m_neighbours.Add(grid.GetTiles()[i + 1, j - 1]);
                }

                if ((i > 0) && (j < grid.GetRows() - 1))
                {
                    m_neighbours.Add(grid.GetTiles()[i - 1, j + 1]);
                }

                if ((i < grid.GetCols() - 1) && (j < grid.GetRows() - 1))
                {
                    m_neighbours.Add(grid.GetTiles()[i + 1, j + 1]);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            gGrid = new GameGrid(40, 40, 8, 8, graphics.GraphicsDevice);
            graphics.PreferredBackBufferWidth  = gGrid.GetCols() * (int)gGrid.GetTileDims().X; // set this value to the desired width of your window
            graphics.PreferredBackBufferHeight = gGrid.GetRows() * (int)gGrid.GetTileDims().Y; // set this value to the desired height of your window
            graphics.ApplyChanges();

            base.Initialize();
            this.IsMouseVisible = true;
        }