Пример #1
0
        /// <summary>
        /// Checks the values for a tile at a specific tileGridPosition.
        /// If one value doesn't match the value within the tiles name false is returned,
        /// while one null-value of the tileValueGrid values is allowed.
        /// </summary>
        /// <param name="tile">The tile whose values should be checked.</param>
        /// <returns>True, if values matching (one tileValueGrid value can be null), false if not.</returns>
        private bool CheckValueGridAtTileGridPosition(TriominoTile tile)
        {
            List <int?> valuesToCheck = this.GetValueGridValuesFromNameGridPositions(tile.TileGridPosition, tile.Orientation.ToArrayTileOrientation());

            // if more than two values are null, this triomino tile
            // isn't added adjacent to another tile (except for the first tile).
            if (this.NumbTilesOnBoard > 0 && valuesToCheck.Where(v => !v.HasValue).Count() > 1)
            {
                return(false);
            }

            string[] nameParts = tile.GetArrayName().Split('-');

            for (int i = 0; i < valuesToCheck.Count; i++)
            {
                int intValue = int.Parse(nameParts[i]);

                if (valuesToCheck[i].HasValue && valuesToCheck[i] != intValue)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Places a Tile on the TileGrid and TileValuesGrid
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        private bool AddTile(TriominoTile tile)
        {
            if (this.GetTileFromGrid(tile.TileGridPosition) != null)
            {
                throw new ArgumentException($"Cannot add tile {tile.Name} at position(x,y): ({tile.TileGridPosition.X}, {tile.TileGridPosition.Y}). Place is taken by tile: '{this.GetTileFromGrid(tile.TileGridPosition).Name}'");
            }

            this.SetTileOnGrid(tile);
            this.AddValuesToValueGrid(tile.GetArrayName(), tile.TileGridPosition, tile.Orientation.ToArrayTileOrientation());
            this.NumbTilesOnBoard++;

            return(true);
        }