Beispiel #1
0
        public void GivenMatchTilesCreated_WhenExecute_ThenAddNewTileToModel()
        {
            matchTileGridModel.gridSize = new Vector2(1, 2);

            MatchTile matchTile = new MatchTile();

            matchTile.canMove    = true;
            matchTile.position   = new Vector2(0, 0);
            matchTile.tileObject = new GameObject();

            MatchTile secondMatchTile = new MatchTile();

            secondMatchTile.canMove    = true;
            secondMatchTile.position   = new Vector2(0, 1);
            secondMatchTile.tileObject = new GameObject();

            Dictionary <Vector2, MatchTile> matchTilesDic = new Dictionary <Vector2, MatchTile> ();

            matchTilesDic [matchTile.position]       = matchTile;
            matchTilesDic [secondMatchTile.position] = secondMatchTile;

            matchTileGridModel.GetMatchTiles().Returns(matchTilesDic);

            shuffleGridCommand.Execute();

            matchTileGridModel.Received(2).AddNewTile(Arg.Any <MatchTile> ());
        }
Beispiel #2
0
        private bool CheckMatches()
        {
            Dictionary <Vector2, MatchTile> matchTiles = matchTileGridModel.GetMatchTiles();

            float yMax = matchTileGridModel.gridSize.y;
            float xMax = matchTileGridModel.gridSize.x;

            for (int y = 0; y < yMax; y++)
            {
                for (int x = 0; x < xMax; x++)
                {
                    Vector2 pos = new Vector2(x, y);
                    if (matchTiles.ContainsKey(pos))
                    {
                        MatchTile matchTile = matchTiles [pos];
                        if (matchTile.canMove)
                        {
                            // Cleaar any hint tiles saved from previous loop.
                            matchTileGridModel.ClearHintMatchTiles();

                            if (ValidMatchTileSequence(matchTile, pos))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
        public void RemoveTileTouched(MatchTile tile)
        {
            tilesTouched.Remove(tile);
            Vector2 prevousPos = tilesTouched [tilesTouched.Count - 1].position;

            lastMatchTileAddedPos = prevousPos;
        }
Beispiel #4
0
        private void CalculateTilesToRemove(List <MatchTile> tilesTouched)
        {
            for (int i = 0; i < tilesTouched.Count; i++)
            {
                MatchTile tile = tilesTouched [i];

                if (tile.tileObject != null)
                {
                    int touchedCount = i + 1;

                    RemoveTile removeTile = new RemoveTile();
                    removeTile.touched    = true;
                    removeTile.matchTiles = new List <MatchTile> ();
                    removeTile.matchTiles.Add(tile);

                    if (touchedCount == tilesTouched.Count)
                    {
                        removeTile.lastInChain  = true;
                        removeTile.tilesChained = touchedCount;
                    }

                    eventDispatcher.Broadcast(MatchTileGridMessage.REMOVE_TILES, removeTile);
                }
            }
        }
Beispiel #5
0
        public void Remove(MatchTile matchTile)
        {
            matchTile.tileObject.transform.DOKill();
            matchTile.tileObject.transform.DOScale(GetTileScale(), 0.3f).OnComplete(() => PoolObject(matchTile));

            matchTileGridModel.RemoveTile(matchTile.position);
        }
Beispiel #6
0
        public void GiveTwoMatchTilesAddedToRemoveTile_WhenExecute_ThenRemoveBothMatchTiles()
        {
            MatchTile matchTile = new MatchTile();

            matchTile.type    = MatchTileType.MatchToken_A;
            matchTile.canMove = true;

            List <MatchTile> matchTiles = new List <MatchTile> ();

            matchTiles.Add(matchTile);
            matchTiles.Add(matchTile);

            RemoveTile removeTile = new RemoveTile();

            removeTile.matchTiles = matchTiles;

            matchTileGridModel.CanMove(matchTile).Returns(true);

            removeMatchTilesCommand.removeTile = removeTile;
            removeMatchTilesCommand.Execute();

            IEnumerator iEnum = removeMatchTilesCommand.enumerator;

            iEnum.MoveNext();
            iEnum.MoveNext();
            iEnum.MoveNext();
            iEnum.MoveNext();

            matchTileFactory.Received(2).RemoveMatchTile(matchTile);
        }
Beispiel #7
0
        public void GivenOneMatchTileInRemoveTile_WhenExecute_ThenClearTilesTouched()
        {
            MatchTile matchTile = new MatchTile();

            matchTile.type    = MatchTileType.MatchToken_A;
            matchTile.canMove = true;

            List <MatchTile> matchTiles = new List <MatchTile> ();

            matchTiles.Add(matchTile);

            RemoveTile removeTile = new RemoveTile();

            removeTile.matchTiles = matchTiles;

            removeMatchTilesCommand.removeTile = removeTile;
            removeMatchTilesCommand.Execute();

            IEnumerator iEnum = removeMatchTilesCommand.enumerator;

            iEnum.MoveNext();
            iEnum.MoveNext();

            IEnumerator loopEnumerator = removeMatchTilesCommand.loopEnumerator;

            loopEnumerator.MoveNext();
            loopEnumerator.MoveNext();

            IEnumerator endEnumerator = removeMatchTilesCommand.endEnumerator;

            endEnumerator.MoveNext();
            endEnumerator.MoveNext();

            matchTileGridModel.Received().ClearTilesTouched();
        }
Beispiel #8
0
        private IEnumerator CreateNewTile(int pos, bool previousAllowTouch)
        {
            yield return(new WaitForSeconds(0.21f));

            bool createMore = false;

            for (int x = 0; x < matchTileGridModel.gridSize.x; x++)
            {
                float y = matchTileGridModel.gridSize.y - 1f;

                Vector2   tilePos   = new Vector2(x, y);
                MatchTile matchTile = matchTileGridModel.GetMatchTile(tilePos);

                if (matchTile == null)
                {
                    createMore = true;

                    matchTileFactory.CreateRandomMatchTile(tilePos);
                }
            }

            if (createMore)
            {
                loopEnumerator = CreateNewTile(pos, previousAllowTouch);
                Coroutiner.StartCoroutine(loopEnumerator);
            }
            else
            {
                AllowTouch(previousAllowTouch);
            }
        }
Beispiel #9
0
        public void GivenOneMatchTileInRemoveTile_WhenExecute_ThenBroadcastRemoveTilesComplete()
        {
            MatchTile matchTile = new MatchTile();

            matchTile.type    = MatchTileType.MatchToken_A;
            matchTile.canMove = true;

            List <MatchTile> matchTiles = new List <MatchTile> ();

            matchTiles.Add(matchTile);

            RemoveTile removeTile = new RemoveTile();

            removeTile.matchTiles = matchTiles;


            removeMatchTilesCommand.removeTile = removeTile;
            removeMatchTilesCommand.Execute();

            IEnumerator iEnum = removeMatchTilesCommand.enumerator;

            iEnum.MoveNext();
            iEnum.MoveNext();

            IEnumerator loopEnumerator = removeMatchTilesCommand.loopEnumerator;

            loopEnumerator.MoveNext();
            loopEnumerator.MoveNext();

            eventDispatcher.Received().Broadcast(MatchTileGridMessage.ALLOW_FALLING_TILES);
        }
Beispiel #10
0
        public void GivenMatchTilesPopulatedWithMatches_WhenExecute_ThenDontShuffleGrid()
        {
            matchTileGridModel.gridSize = new Vector2(2, 2);

            Vector2 first  = new Vector2(0, 0);
            Vector2 second = new Vector2(0, 1);
            Vector2 third  = new Vector2(1, 0);
            Vector2 fourth = new Vector2(1, 1);

            MatchTile firstMatch   = CreateMatchTile(MatchTileType.MatchToken_A, first);
            MatchTile secondMatch  = CreateMatchTile(MatchTileType.MatchToken_A, second);
            MatchTile thirdMatch   = CreateMatchTile(MatchTileType.MatchToken_A, third);
            MatchTile fourthMMatch = CreateMatchTile(MatchTileType.MatchToken_A, fourth);

            Dictionary <Vector2, MatchTile> matchTilesDic = new Dictionary <Vector2, MatchTile> ();

            matchTilesDic [first]  = firstMatch;
            matchTilesDic [second] = secondMatch;
            matchTilesDic [third]  = thirdMatch;
            matchTilesDic [fourth] = fourthMMatch;

            matchTileGridModel.GetMatchTiles().Returns(matchTilesDic);

            matchTileGridModel.GetMatchTile(first).Returns(matchTilesDic [first]);
            matchTileGridModel.GetMatchTile(second).Returns(matchTilesDic [second]);
            matchTileGridModel.GetMatchTile(third).Returns(matchTilesDic [third]);
            matchTileGridModel.GetMatchTile(fourth).Returns(matchTilesDic [fourth]);

            matchTileGridModel.GetHintMatchTiles().Returns(new List <MatchTile>());

            checkMovesRemainingCommand.Execute();

            eventDispatcher.DidNotReceive().Broadcast(MatchTileGridMessage.SHUFFLE_GRID);
        }
Beispiel #11
0
        private void RemoveTiles()
        {
            Dictionary <Vector2, MatchTile> matchTiles = matchTileGridModel.GetMatchTiles();

            float yMax = matchTileGridModel.gridSize.y;
            float xMax = matchTileGridModel.gridSize.x;

            for (int y = 0; y < yMax; y++)
            {
                for (int x = 0; x < xMax; x++)
                {
                    Vector2 pos = new Vector2(x, y);
                    if (matchTiles.ContainsKey(pos))
                    {
                        MatchTile matchTile = matchTiles [pos];
                        if (matchTile.canMove)
                        {
                            matchTileList.Add(matchTile);
                            matchTilePositions.Add(pos);

                            matchTileGridModel.RemoveTile(pos);
                        }
                    }
                }
            }
        }
Beispiel #12
0
        public void GivenShowAllTilesAllowTouchFalse_WhenExecute_ThenDoNotShowAllMatchTiles()
        {
            matchTileGridModel.allowTouch = false;

            MatchTile matchTile = new MatchTile();

            matchTile.canTouch   = true;
            matchTile.position   = Vector2.zero;
            matchTile.tileObject = new GameObject();

            Dictionary <Vector2, MatchTile> matchTilesDic = new Dictionary <Vector2, MatchTile> ();

            matchTilesDic [matchTile.position] = matchTile;

            matchTileGridModel.GetMatchTiles().Returns(matchTilesDic);

            IMatchTileComponent matchTileComponenet = Substitute.For <IMatchTileComponent> ();

            matchTileGridModel.GetMatchTileComponent(Arg.Any <MatchTile>()).Returns(matchTileComponenet);

            hideInvalidTilesCommand.hideType = HideType.ShowAll;
            hideInvalidTilesCommand.Execute();

            matchTileComponenet.DidNotReceive().Show();
        }
Beispiel #13
0
		private void Remove(MatchTile matchTile, RemoveTile removeTile)
		{	
			if (matchTileGridModel.CanMove(matchTile) )
			{
				tilesToReplace++;
				matchTileFactory.RemoveMatchTile (matchTile);	
			}
		}
Beispiel #14
0
        private void HighLight(MatchTile tile)
        {
            IMatchTileComponent matchTileComponent = matchTileGridModel.GetMatchTileComponent(tile);

            if (matchTileComponent != null)
            {
                matchTileComponent.HighLight();
            }
        }
Beispiel #15
0
        private MatchTile CreateMatchTile(MatchTileType type, Vector2 position)
        {
            MatchTile tile = new MatchTile();

            tile.canMove  = true;
            tile.type     = type;
            tile.position = position;

            return(tile);
        }
Beispiel #16
0
        public void AddTileTouched(Vector2 pos, MatchTile matchTile)
        {
            if (tilesTouched.Count == 0)
            {
                selectedMatchTileType = matchTile.type;
            }

            tilesTouched.Add(matchTile);
            lastMatchTileAddedPos = pos;
        }
Beispiel #17
0
        private void DisplayHint()
        {
            List <MatchTile> hintMatchTiles = matchTileGridModel.GetHintMatchTiles();

            for (int i = 0; i < hintMatchTiles.Count; i++)
            {
                MatchTile tile = hintMatchTiles [i];

                IMatchTileComponent matchTileComponent = matchTileGridModel.GetMatchTileComponent(tile);
                matchTileComponent.Hint(i);
            }
        }
Beispiel #18
0
        public bool CanMove(MatchTile tile)
        {
            if (tile != null)
            {
                if (!ValidMatchTile(tile.type))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #19
0
        public MatchTile Create(MatchTileType type, Vector2 position)
        {
            MatchTile matchTile = new MatchTile();

            matchTile.position   = position;
            matchTile.type       = type;
            matchTile.canMove    = matchTileGridModel.CanMove(matchTile);
            matchTile.canTouch   = matchTileGridModel.ValidMatchTile(matchTile.type);
            matchTile.tileObject = CreateTileGameObject(type, position);
            matchTileGridModel.AddNewTile(matchTile);

            return(matchTile);
        }
Beispiel #20
0
        public void MoveTile(Vector2 currentPosition, Vector2 newPosition)
        {
            MatchTile tile = GetMatchTile(currentPosition);

            if (tile != null && tile.canMove)
            {
                RemoveTile(currentPosition);

                tile.position = newPosition;

                AddNewTile(tile);
            }
        }
Beispiel #21
0
        private void ShowAllTiles()
        {
            Dictionary <Vector2, MatchTile> matchTiles = matchTileGridModel.GetMatchTiles();

            foreach (KeyValuePair <Vector2, MatchTile> entry in matchTiles)
            {
                MatchTile           tile = entry.Value;
                IMatchTileComponent matchTileComponent = matchTileGridModel.GetMatchTileComponent(tile);
                if (matchTileComponent != null)
                {
                    matchTileComponent.Show();
                }
            }
        }
Beispiel #22
0
        private void HideNotValidTiles()
        {
            List <MatchTile> matchTiles = matchTileGridModel.GetAllMatchTilesNotOfType(type);

            for (int i = 0; i < matchTiles.Count; i++)
            {
                MatchTile           tile = matchTiles [i];
                IMatchTileComponent matchTileComponent = matchTileGridModel.GetMatchTileComponent(tile);
                if (matchTileComponent != null)
                {
                    matchTileComponent.Hide();
                }
            }
        }
Beispiel #23
0
        private void AddTilesToNewPositions()
        {
            for (int i = 0; i < matchTileList.Count; i++)
            {
                int     random = Random.Range(0, matchTilePositions.Count);
                Vector2 newPos = matchTilePositions [random];

                MatchTile tile = matchTileList [i];
                tile.position = newPos;
                tile.tileObject.transform.DOLocalMove(newPos, matchTileGridModel.moveSpeed).SetEase(Ease.Linear);
                matchTileGridModel.AddNewTile(tile);

                matchTilePositions.Remove(newPos);
            }
        }
Beispiel #24
0
        private void DisplayTiles(List <MatchTile> tilesTouched)
        {
            for (int i = 0; i < tilesTouched.Count; i++)
            {
                MatchTile tile = tilesTouched [i];

                if (tile.tileObject != null)
                {
                    IMatchTileComponent matchTileComponent = matchTileGridModel.GetMatchTileComponent(tile);
                    if (matchTileComponent != null)
                    {
                        matchTileComponent.Tile();
                    }
                }
            }
        }
Beispiel #25
0
        public List <MatchTile> GetAllMatchTilesNotOfType(MatchTileType type)
        {
            List <MatchTile> tiles = new List <MatchTile> ();

            foreach (KeyValuePair <Vector2, MatchTile> entry in GetMatchTiles())
            {
                MatchTile tile = entry.Value;

                if (!tile.type.Equals(type) && tile.canTouch)
                {
                    tiles.Add(tile);
                }
            }

            return(tiles);
        }
Beispiel #26
0
        public void GivenValidMoveTouchEndedTrue_WhenExecute_ThenBroadcastRemoveTiles()
        {
            MatchTile tile = new MatchTile();

            tile.tileObject = new GameObject();

            List <MatchTile> matchTiles = new List <MatchTile> ();

            matchTiles.Add(tile);

            matchTileGridModel.GetTilesTouched().Returns(matchTiles);
            matchTileGridModel.ValidMoveTouchEnded().Returns(true);

            calculateTilesToRemoveCommand.Execute();

            eventDispatcher.Received().Broadcast(MatchTileGridMessage.REMOVE_TILES, Arg.Any <RemoveTile> ());
        }
Beispiel #27
0
        public void GivenCanTouchTile_WhenTouchObjectExecute_ThenAddTileTouchedToModel()
        {
            matchTileGridModel.allowTouch = true;

            MatchTile matchTile = new MatchTile();

            matchTile.canTouch   = true;
            matchTile.position   = Vector2.zero;
            matchTile.tileObject = new GameObject();

            matchTileGridModel.GetMatchTile(Vector2.zero).Returns(matchTile);
            matchTileGridModel.CanTouchTile(matchTile).Returns(true);

            matchTileTouchedCommand.Execute();

            matchTileGridModel.Received().AddTileTouched(Arg.Any <Vector2> (), Arg.Any <MatchTile> ());
        }
Beispiel #28
0
        public void GivenCanTouchTile_WhenTouchObjectExecute_ThenBroadcastTileSelected()
        {
            matchTileGridModel.allowTouch = true;

            MatchTile matchTile = new MatchTile();

            matchTile.canTouch   = true;
            matchTile.position   = Vector2.zero;
            matchTile.tileObject = new GameObject();

            matchTileGridModel.GetMatchTile(Vector2.zero).Returns(matchTile);
            matchTileGridModel.CanTouchTile(matchTile).Returns(true);

            matchTileTouchedCommand.Execute();

            eventDispatcher.Received().Broadcast(MatchTileGridMessage.TILE_SELECTED, Arg.Any <MatchTileType> ());
        }
Beispiel #29
0
        private bool MoveTo(Vector2 moveToPosition, Vector2 currentPos, MatchTile newTile)
        {
            if (newTile == null &&
                moveToPosition.y >= 0 &&
                moveToPosition.y < matchTileGridModel.gridSize.y &&
                moveToPosition.x >= 0 &&
                moveToPosition.x < matchTileGridModel.gridSize.x)
            {
                MatchTile currentTile = matchTileGridModel.GetMatchTile(currentPos);
                if (currentTile.canMove)
                {
                    currentTile.tileObject.transform.DOLocalMove(moveToPosition, matchTileGridModel.moveSpeed).SetEase(Ease.Linear);
                    matchTileGridModel.MoveTile(currentPos, moveToPosition);
                    return(true);
                }
            }

            return(false);
        }
Beispiel #30
0
        /****************** Grid Scanning ******************/

        public bool CheckIfMoveAbove(Vector2 currentPos)
        {
            for (int y = (int)currentPos.y; y < gridSize.y; y++)
            {
                Vector2 pos = new Vector2(currentPos.x, y);

                MatchTile matchTile = GetMatchTile(pos);
                if (matchTile != null)
                {
                    if (!CanMove(matchTile))
                    {
                        return(false);
                    }

                    return(true);
                }
            }

            return(true);
        }