Ejemplo n.º 1
0
        private void BoardModelOnTileSwapped(TilePosition position1, TilePosition position2)
        {
            if (_matrix[position1.Row, position1.Col].Tile.IsDeleted == false)
            {
                var destination = GetTileDrawPosition(position2.Row, position2.Col);
                _animations.Add(new MoveTileAnimation(450, _matrix[position1.Row, position1.Col],
                                                      destination));
            }

            if (_matrix[position2.Row, position2.Col].Tile.IsDeleted == false)
            {
                var destination = GetTileDrawPosition(position1.Row, position1.Col);
                _animations.Add(new MoveTileAnimation(450, _matrix[position2.Row, position2.Col],
                                                      destination));
            }

            var tmp = _matrix[position1.Row, position1.Col];

            _matrix[position1.Row, position1.Col] = _matrix[position2.Row, position2.Col];
            _matrix[position2.Row, position2.Col] = tmp;
        }
Ejemplo n.º 2
0
        private List <TilePosition> FindMatch(TilePosition position)
        {
            var checkedTile = Matrix[position.Row, position.Col];

            var positions1 = new List <TilePosition> {
                position
            };

            for (var i = position.Col + 1; i < Columns; i++)
            {
                if (Matrix[position.Row, i]?.Type == checkedTile.Type)
                {
                    positions1.Add(new TilePosition(position.Row, i));
                    continue;
                }

                break;
            }

            for (var i = position.Col - 1; i >= 0; i--)
            {
                if (Matrix[position.Row, i]?.Type == checkedTile.Type)
                {
                    positions1.Add(new TilePosition(position.Row, i));
                    continue;
                }

                break;
            }

            var positions2 = new List <TilePosition> {
                position
            };

            for (var i = position.Row + 1; i < Rows; i++)
            {
                if (Matrix[i, position.Col]?.Type == checkedTile.Type)
                {
                    positions2.Add(new TilePosition(i, position.Col));
                    continue;
                }

                break;
            }

            for (var i = position.Row - 1; i >= 0; i--)
            {
                if (Matrix[i, position.Col]?.Type == checkedTile.Type)
                {
                    positions2.Add(new TilePosition(i, position.Col));
                    continue;
                }

                break;
            }

            if (positions1.Count >= 3 && positions1.Count >= positions2.Count)
            {
                return(positions1);
            }

            if (positions2.Count >= 3)
            {
                return(positions2);
            }

            return(null);
        }
Ejemplo n.º 3
0
        private void BoardModelOnTileDeleted(Tile tile, TilePosition position)
        {
            var destination = new Vector2(-TileView.TextureSize.X * 2, -TileView.TextureSize.Y * 2);

            _animations.Add(new MoveTileAnimation(350, _matrix[position.Row, position.Col], destination));
        }
Ejemplo n.º 4
0
 private bool IsNearTile(TilePosition position1, TilePosition position2)
 {
     return(Math.Abs(position1.Row - position2.Row) + Math.Abs(position1.Col - position2.Col) < 2);
 }