Example #1
0
        /// <summary>
        /// Add a wall between two cells to the Board.
        /// </summary>
        /// <param name="cell1Col">Column of the first cell adjacent to the wall</param>
        /// <param name="cell1Row">Row of the first cell adjacent to the wall</param>
        /// <param name="cell2Col">Column of the second cell adjacent to the wall</param>
        /// <param name="cell2Row">Row of the second cell adjacent to the wall</param>
        public void AddWallToBoard(int cell1Col, int cell1Row, int cell2Col, int cell2Row)
        {
            this.BoardWalls.AddWall(cell1Col, cell1Row, cell2Col, cell2Row);

            if (this.WallAddedToBoardEvent != null)
            {
                this.WallAddedToBoardEvent(cell1Col, cell1Row, BoardWalls.CalculatePositionOfWall(cell1Col, cell1Row, cell2Col, cell2Row), null);
            }
        }
Example #2
0
        /// <summary>
        /// Check if an object moving from one cell to another would run into a wall between those cells.
        /// </summary>
        /// <param name="fromCellCol">Column of the cell the object is moving from</param>
        /// <param name="fromCellRow">Row of the cell the object is moving from</param>
        /// <param name="toCellCol">Column of the cell the object is moving to</param>
        /// <param name="toCellRow">Row of the cell the object is moving to</param>
        /// <returns>True if there is a wall between the 'from cell' and 'to cell'</returns>
        public bool WouldHitWall(int fromCellCol, int fromCellRow, int toCellCol, int toCellRow)
        {
            VerifyCellPositionParams(fromCellCol, fromCellRow);
            VerifyCellPositionParams(toCellCol, toCellRow);

            WallPositionFlags expectedDirection = BoardWalls.CalculatePositionOfWall(fromCellCol, fromCellRow, toCellCol, toCellRow);
            WallPositionFlags wallsForCell      = boardWallMap[fromCellCol, fromCellRow];

            return(wallsForCell.HasFlag(expectedDirection));
        }
Example #3
0
        /// <summary>
        /// Add a wall to the Board between two cells
        /// </summary>
        /// <param name="cell1Col">Column of the first cell the wall is between</param>
        /// <param name="cell1Row">Row of the first cell the wall is between</param>
        /// <param name="cell2Col">Column of the second cell the wall is between</param>
        /// <param name="cell2Row">Row of the second cell the wall is between</param>
        public void AddWall(int cell1Col, int cell1Row, int cell2Col, int cell2Row)
        {
            VerifyCellPositionParams(cell1Col, cell1Row);
            VerifyCellPositionParams(cell2Col, cell2Row);
            if (cell1Col == cell2Col && cell1Row == cell2Row)
            {
                throw new ArgumentException("Cells cannot be the same for wall placement!");
            }

            // Save the wall info on both cells, but opposite directions
            boardWallMap[cell1Col, cell1Row] &= BoardWalls.CalculatePositionOfWall(cell1Col, cell1Row, cell2Col, cell2Row);
            boardWallMap[cell2Col, cell2Row] &= BoardWalls.CalculatePositionOfWall(cell2Col, cell2Row, cell1Col, cell1Row);
        }