示例#1
0
        private void StartCheckingForMove(MatchingTile tile, MatchingTile tile2)
        {
            var tiles = Grid.GetValidTilesGroup(tile);

            tiles.AddRange(Grid.GetValidTilesGroup(tile2));
            if (tiles.Count < MinimumAmountOfGroupedTiles)
            {
                return;
            }

            _audioSource.PlayOneShot(OnMoveSounds[UnityEngine.Random.Range(0, OnMoveSounds.Length)]);
            Grid.PerformMove(tiles, OnExplosionParticles);

            OnMoveParticles.transform.position = new Vector3(tile.transform.position.x, tile.transform.position.y, tile.transform.position.z - 1f);
            OnMoveParticles.Play();

            var score = CalculateScore(tiles.Count);

            ScorePopupText.text           = "+" + score;
            ScorePopup.transform.position = Camera.main.WorldToScreenPoint(tile.transform.position);
            ScorePopup.EnableFor(0.5f);
            OnScoreParticles.transform.position = new Vector3(tile.transform.position.x, tile.transform.position.y, tile.transform.position.z - 1f);
            OnScoreParticles.Play();
            ScoreCounter.AddScore(score);
        }
示例#2
0
        private void ManageMove2(MatchingTile tile)
        {
            if (_canMove)
            {
                if (_currentSelectedTile == null)
                {
                    _currentSelectedTile = tile;
                    return;
                }

                _targetSelectedTile = tile;

                if (_currentSelectedTile == _targetSelectedTile)
                {
                    ClearMove();
                    return;
                }

                if (_targetSelectedTile.IsNearTo(_currentSelectedTile))
                {
                    _canMove = false;
                    // Here the move is valid and it can start.
                    Grid.ExchangeTiles(_currentSelectedTile, _targetSelectedTile, OnExchangingCompleted);
                }
                else
                {
                    ClearMove();
                    return;
                }
            }
        }
示例#3
0
        public void ExchangeTiles(MatchingTile tile1, MatchingTile tile2, Action <object> onCompleteAction)
        {
            var position1 = tile1.transform.position;
            var position2 = tile2.transform.position;

            ExchangeTilesGridPosition(tile1, tile2);

            var tiles = new MatchingTile[] { tile1, tile2 };

            iTween.MoveTo(tile1.gameObject, iTween.Hash(
                              "position", position2,
                              "easetype", iTween.EaseType.easeInBack,
                              "time", 0.5f
                              ));
            iTween.MoveTo(tile2.gameObject, iTween.Hash(
                              "position", position1,
                              "easetype", iTween.EaseType.easeInBack,
                              "time", 0.5f,
                              "oncomplete", onCompleteAction,
                              "oncompleteparams", tiles
                              ));

            /*var position1 = new Vector3(tile2.transform.position.x, tile2.transform.position.y, tile2.transform.position.z);
             * var gridPosition1 = new Vector2(tile2.GridPosition.x, tile2.GridPosition.y);
             *
             * tile2.GridPosition = tile1.GridPosition;
             * tile2.transform.position = tile1.transform.position;
             * tile1.GridPosition = gridPosition1;
             * tile1.transform.position = position1;
             *
             * _grid[(int)tile2.GridPosition.x, (int)tile2.GridPosition.y] = tile2;
             * _grid[(int)tile1.GridPosition.x, (int)tile1.GridPosition.y] = tile1;*/
        }
示例#4
0
        public void ExchangeTilesGridPosition(MatchingTile tile1, MatchingTile tile2)
        {
            var gridPosition1 = new Vector2(tile1.GridPosition.x, tile1.GridPosition.y);

            tile1.GridPosition = new Vector2(tile2.GridPosition.x, tile2.GridPosition.y);
            tile2.GridPosition = gridPosition1;

            _grid[(int)tile2.GridPosition.x, (int)tile2.GridPosition.y] = tile2;
            _grid[(int)tile1.GridPosition.x, (int)tile1.GridPosition.y] = tile1;
        }
示例#5
0
        public List <MatchingTile> GetValidTilesGroup(MatchingTile startingTile)
        {
            var tiles = new List <MatchingTile> {
                startingTile
            };

            GetValidNeighbours(startingTile, ref tiles);

            return(tiles);
        }
示例#6
0
        private void GetValidNeighbours(MatchingTile tile, ref List <MatchingTile> neighbours)
        {
            for (int i = -1; i < 2; i++)
            {
                int index = (int)tile.GridPosition.x + i;
                if (index < 0 || index >= _size.x)
                {
                    continue;
                }
                var neighbour = _grid[index, (int)tile.GridPosition.y];

                if (neighbour == null)
                {
                    continue;
                }

                if (neighbour.Type == tile.Type)
                {
                    if (neighbours.Contains(neighbour))
                    {
                        continue;
                    }
                    neighbours.Add(neighbour);
                    GetValidNeighbours(neighbour, ref neighbours);
                }
            }

            for (int i = -1; i < 2; i++)
            {
                int index = (int)tile.GridPosition.y + i;
                if (index < 0 || index >= _size.y)
                {
                    continue;
                }
                var neighbour = _grid[(int)tile.GridPosition.x, index];

                if (neighbour == null)
                {
                    continue;
                }

                if (neighbour.Type == tile.Type)
                {
                    if (neighbours.Contains(neighbour))
                    {
                        continue;
                    }
                    neighbours.Add(neighbour);
                    GetValidNeighbours(neighbour, ref neighbours);
                }
            }
        }
示例#7
0
        public bool IsNearTo(MatchingTile tile)
        {
            int thisX      = (int)GridPosition.x;
            int thisY      = (int)GridPosition.y;
            int neighbourX = (int)tile.GridPosition.x;
            int neighbourY = (int)tile.GridPosition.y;

            if (thisX == neighbourX)
            {
                if (neighbourY == thisY - 1)
                {
                    return(true);
                }
                if (neighbourY == thisY)
                {
                    return(true);
                }
                if (neighbourY == thisY + 1)
                {
                    return(true);
                }
            }
            if (thisY == neighbourY)
            {
                if (neighbourX == thisX - 1)
                {
                    return(true);
                }
                if (neighbourX == thisX)
                {
                    return(true);
                }
                if (neighbourX == thisX + 1)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#8
0
 private void ClearMove()
 {
     _currentSelectedTile = null;
     _targetSelectedTile  = null;
 }
示例#9
0
 public void PopTile(MatchingTile tile)
 {
     _grid[(int)tile.GridPosition.x, (int)tile.GridPosition.y] = null;
     _tilesCounter--;
     GameObject.Destroy(tile.gameObject);
 }