示例#1
0
        private void BlockEndMoveHandler(Tetromino tetromino)
        {
            if (CanAddToGrid(tetromino))
            {
                tetromino.FinishMove();
                tetromino.OnBlockEndMove -= BlockEndMoveHandler;
                _spawner.Remove(tetromino);

                AddTetrominoToGrid(tetromino);
                // TODO i deleted destroyed tetromino after adding to grid then need think about what do with tetromino after add and HOW add

                // TODO made clearing after ending adding to grid animation
                TryClearFullLinesAndColumns();

                // TODO create new tetrominoes after ending animation of clearing
                _spawner.TryCreateTetrominoes();

                if (!CanAddAtLeastOneLiveTetrominoToGrid())
                {
                    OnGameOver?.Invoke();
                }
            }
            else
            {
                tetromino.Reset();
            }
        }
示例#2
0
        public void AddTetrominoToGrid(Tetromino tetromino)
        {
            foreach (Transform block in tetromino.Blocks)
            {
                // TODO move this code to gridView
                (int x, int y)coord = _gridView.GetCoordinatesOnGrid(block.position);
                block.position      = new Vector3(coord.x, coord.y, block.position.z);
                block.parent        = _gridView.transform;
                tetromino.SetSortingLayerForAllBlocks(SortingLayerConstants.PieceLayer);
                _grid[coord.x, coord.y].Block = block.gameObject;
            }

            BlockAdded?.Invoke(tetromino.GetScore());
        }
示例#3
0
        public bool HasPlaceForTetromino(Tetromino tetromino)
        {
            for (int y = 0; y < Grid.Height; y++)
            {
                for (int x = 0; x < Grid.Width; x++)
                {
                    if (CanAddToGridByPosition(tetromino, (x, y)))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#4
0
        public bool CanAddToGrid(Tetromino tetromino)
        {
            foreach (Transform block in tetromino.Blocks)
            {
                (int x, int y)coord = _gridView.GetCoordinatesOnGrid(block.position);

                if (!_grid.IsCoordinateOnGrid(coord))
                {
                    return(false);
                }
                if (_grid[coord.y, coord.x].IsEmpty == false)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#5
0
 private bool CanAddToGridByPosition(Tetromino tetromino, (int x, int y) gridPosition)