public void Init()
        {
            for (int row = 0; row < _configuration.LevelHeight; row++)
            {
                for (int column = 0; column < _configuration.LevelWidth; column++)
                {
                    EcsEntity  cellEntity = _world.NewEntity();
                    Vector2Int position   = new Vector2Int(column, row);
                    cellEntity.Set <Vector2Int>() = position;

                    bool hasChain = true;
                    int  tryCount = 0;

                    _gameField.Cells.Add(position, cellEntity);

                    while (hasChain && tryCount < 100)
                    {
                        tryCount++;

                        float             random        = Random.Range(0f, 100f);
                        CellConfiguration configuration = _configuration.CellConfigurations.Where(c => c.CheckInSpawnRabge(random)).First();

                        cellEntity.Set <Cell>().Configuration = configuration;

                        hasChain = GameFieldAnalyst.CheckCellInChain(_gameField.Cells, _configuration, position);
                    }
                }
            }
        }
Esempio n. 2
0
        public void Run()
        {
            if (_changeField.GetEntitiesCount() > 0)
            {
                _fieldChanged = true;
            }
            else if (_fieldChanged)
            {
                _fieldChanged = false;
                List <ChainEvent> chains = GameFieldAnalyst.GetChains(_gameField.Cells, _configuration);

                for (int i = 0; i < chains.Count; i++)
                {
                    AddChain(chains[i].Position, chains[i].Direction, chains[i].Size);
                }
            }
        }
Esempio n. 3
0
        public void Run()
        {
            if (_fieldChangers.GetEntitiesCount() > 0 || _chains.GetEntitiesCount() > 0 || _explosionAnimations.GetEntitiesCount() > 0)
            {
                return;
            }

            foreach (int index in _filter)
            {
                Vector2Int cellPosition   = _filter.Get2(index);
                Vector2Int targetPosition = _filter.Get3(index).To;

                EcsEntity swapCell   = _filter.GetEntity(index);
                EcsEntity secondCell = _gameField.Cells[targetPosition];

                swapCell.Set <Vector2Int>() = targetPosition;
                swapCell.Set <AnimateSwapRequest>().MainCell = true;

                secondCell.Set <Vector2Int>() = cellPosition;
                secondCell.Set <AnimateSwapRequest>().MainCell = false;

                _gameField.Cells[cellPosition]   = secondCell;
                _gameField.Cells[targetPosition] = swapCell;

                List <ChainEvent> chains = GameFieldAnalyst.GetChains(_gameField.Cells, _configuration);

                if (chains.Count == 0)
                {
                    _gameField.Cells[cellPosition]   = swapCell;
                    _gameField.Cells[targetPosition] = secondCell;

                    swapCell.Set <Vector2Int>() = cellPosition;

                    AnimateSwapBackRequest request = new AnimateSwapBackRequest();
                    request.TargetPosition = targetPosition;
                    swapCell.Set <AnimateSwapBackRequest>() = request;

                    secondCell.Set <Vector2Int>() = targetPosition;

                    AnimateSwapBackRequest secondRequest = new AnimateSwapBackRequest();
                    secondRequest.TargetPosition = cellPosition;
                    secondCell.Set <AnimateSwapBackRequest>() = secondRequest;
                }
            }
        }