Exemplo n.º 1
0
        private Dictionary <Entity, int> CalculateCellsOffsets(GameFieldSize gameSettings)
        {
            GravityDirection         gravityDirection = _helper.Gravity;
            CellsMap                 map            = new CellsMap(EntityManager);
            Dictionary <Entity, int> offsettedCells = new Dictionary <Entity, int>();
            var i = new IntIterator(new IteratorSettings(0, gameSettings.Width - 1, 1));

            while (i.MoveNext())
            {
                var j = new IntIterator(new IteratorSettings(0, gameSettings.Height - 1, -(int)gravityDirection));
                while (j.MoveNext())
                {
                    if (map.GetCell(i, j, out var cell))
                    {
                        continue;
                    }

                    var k = new IntIterator(new IteratorSettings(
                                                j - (int)gravityDirection,
                                                IteratorSettings.GetTo(0, gameSettings.Height - 1, -(int)gravityDirection),
                                                -(int)gravityDirection));
                    while (k.MoveNext())
                    {
                        if (!map.GetCell(i, k, out var affectedCell))
                        {
                            continue;
                        }

                        if (!offsettedCells.TryGetValue(affectedCell, out var o))
                        {
                            offsettedCells[affectedCell] = 0;
                        }

                        offsettedCells[affectedCell] += (int)gravityDirection;
                    }
                }
            }

            return(offsettedCells);
        }