Beispiel #1
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));
        }
 /// <summary>
 /// Callback for the event fired when a wall is added to the game Board.
 /// </summary>
 /// <param name="cellCol">Column for one of the cells the wall borders</param>
 /// <param name="cellRow">Row for one of the cells the wall borders</param>
 /// <param name="wallPosition">Position the wall is relative to the given cell</param>
 /// <param name="eventArgs">Event args (unused)</param>
 private void Wall_AddedToBoardCallback(int cellCol, int cellRow, WallPositionFlags wallPosition, EventArgs eventArgs)
 {
     if (wallPosition == WallPositionFlags.Left || wallPosition == WallPositionFlags.Right)
     {
         UiBuilder.AddItemToGrid(this.DynamicVertWallPanel,
                                 this.uiBuilder.CreateVerticalWallImage(cellCol, cellRow, wallPosition));
     }
     else if (wallPosition == WallPositionFlags.Up || wallPosition == WallPositionFlags.Down)
     {
         UiBuilder.AddItemToGrid(this.DynamicHorizWallPanel,
                                 this.uiBuilder.CreateHorizontalWallImage(cellCol, cellRow, wallPosition));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Create an Image object representing a horizontal wall at a position.
        /// </summary>
        /// <param name="cellCol">Column of the cell where the wall lives</param>
        /// <param name="cellRow">Row of the cell where the wall lives</param>
        /// <param name="wallPosition">Position in the cell where the wall lives</param>
        /// <returns>Image object</returns>
        public Image CreateHorizontalWallImage(int cellCol, int cellRow, WallPositionFlags wallPosition)
        {
            int xPosition = cellCol * this.CellWidthInPx;
            int yPosition = cellRow * this.CellHeightInPx + (wallPosition == WallPositionFlags.Up ? 0 : this.CellHeightInPx) - 2;

            Image horizWall = new Image
            {
                Source              = new BitmapImage(new Uri(@"ms-appx:/Assets/wall_horiz.png")),
                Width               = this.CellWidthInPx,
                Height              = 4,
                Visibility          = Visibility.Visible,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Margin              = new Thickness(xPosition, yPosition, 0, 0)
            };

            return(horizWall);
        }