Ejemplo n.º 1
0
        public void ApplyGravity()
        {
            var newRows = new List<BlockRow>();
            
            var lowerRow = _rows.FirstOrDefault();
            foreach(var higherRow in _rows.Skip(1))
            {
                if (higherRow == null || lowerRow == null)
                    return;

                var newHigherRow = new BlockRow();
                var newLowerRow = new BlockRow();

                var higherRowEnumerator = higherRow.Cells.GetEnumerator();
                var lowerRowEnumerator = lowerRow.Cells.GetEnumerator();

                int x_position = 0;
                while(higherRowEnumerator.MoveNext() || lowerRowEnumerator.MoveNext())
                {
                    if (lowerRowEnumerator.Current && higherRowEnumerator.Current)
                        newHigherRow.AddBlock(x_position); 
                    
                    if (lowerRowEnumerator.Current || higherRowEnumerator.Current)
                        newLowerRow.AddBlock(x_position);

                    x_position++;
                }

                newRows.Add(newLowerRow);
                lowerRow = newHigherRow;
            }

            _rows = newRows;
        }
Ejemplo n.º 2
0
        public BlockBoard(IEnumerable<IEnumerable<bool>> grid)
        {
            _rows = new List<BlockRow>();

            foreach (var row in grid)
            {
                var blockRow = new BlockRow(row.Count());

                var yPosition = 0;
                foreach (var cell in row)
                {
                    if (cell)
                        blockRow.AddBlock(yPosition);

                    yPosition++;
                }

                _rows.Add(blockRow);
            }
        }
Ejemplo n.º 3
0
        public void ApplyGravity()
        {
            var newRows = new List <BlockRow>();

            var lowerRow = _rows.FirstOrDefault();

            foreach (var higherRow in _rows.Skip(1))
            {
                if (higherRow == null || lowerRow == null)
                {
                    return;
                }

                var newHigherRow = new BlockRow();
                var newLowerRow  = new BlockRow();

                var higherRowEnumerator = higherRow.Cells.GetEnumerator();
                var lowerRowEnumerator  = lowerRow.Cells.GetEnumerator();

                int x_position = 0;
                while (higherRowEnumerator.MoveNext() || lowerRowEnumerator.MoveNext())
                {
                    if (lowerRowEnumerator.Current && higherRowEnumerator.Current)
                    {
                        newHigherRow.AddBlock(x_position);
                    }

                    if (lowerRowEnumerator.Current || higherRowEnumerator.Current)
                    {
                        newLowerRow.AddBlock(x_position);
                    }

                    x_position++;
                }

                newRows.Add(newLowerRow);
                lowerRow = newHigherRow;
            }

            _rows = newRows;
        }
Ejemplo n.º 4
0
        public BlockBoard(IEnumerable <IEnumerable <bool> > grid)
        {
            _rows = new List <BlockRow>();

            foreach (var row in grid)
            {
                var blockRow = new BlockRow(row.Count());

                var yPosition = 0;
                foreach (var cell in row)
                {
                    if (cell)
                    {
                        blockRow.AddBlock(yPosition);
                    }

                    yPosition++;
                }

                _rows.Add(blockRow);
            }
        }