Пример #1
0
        public void DropPowerups(Player player)
        {
            FieldCellSlot[] slots      = new FieldCellSlot[GetWidth() * GetHeight()];
            int             slotsCount = GetEmptySlots(slots);

            if (slotsCount == 0)
            {
                return;
            }

            ShuffleSlots(slots, slotsCount);

            PowerupList powerups  = player.powerups;
            int         slotIndex = 0;

            for (int powerupIndex = 0; powerupIndex < Powerups.Count && slotIndex < slots.Length; ++powerupIndex)
            {
                int count = powerups.GetCount(powerupIndex);
                for (int i = 0; i < count && slotIndex < slots.Length; ++i)
                {
                    FieldCellSlot slot = slots[slotIndex++];
                    PowerupCell   cell = new PowerupCell(powerupIndex, slot.cx, slot.cy);
                    AddCell(cell);
                }
            }
        }
Пример #2
0
        private bool CheckStillCollisions(MovableCell movable, FieldCellSlot slot)
        {
            if (slot != null)
            {
                FieldCell staticCell = slot.staticCell;
                if (staticCell != null)
                {
                    return(CheckCollision(movable, staticCell));
                }

                bool handled = false;

                List <MovableCell> movableCells = slot.movableCells;
                for (int i = 0; i < movableCells.Count; ++i)
                {
                    MovableCell other = movableCells[i];
                    if (!other.IsMoving() && movable != other)
                    {
                        handled |= CheckCollision(movable, other);
                    }
                }

                return(handled);
            }

            return(false);
        }
Пример #3
0
        /* Returns true if can be spread more */
        private bool SetFlame(Bomb bomb, int cx, int cy)
        {
            if (!IsInsideField(cx, cy))
            {
                return(false);
            }

            FieldCellSlot slot = GetSlot(cx, cy);

            FieldCell staticCell = slot.staticCell;

            if (staticCell != null)
            {
                if (staticCell.IsSolid())
                {
                    return(false);
                }

                if (staticCell.IsBrick())
                {
                    BrickCell brick = staticCell.AsBrick();
                    if (!brick.destroyed)
                    {
                        brick.Destroy();
                    }

                    return(false);
                }

                if (staticCell.IsPowerup())
                {
                    staticCell.AsPowerup().RemoveFromField();
                    return(false);
                }
            }

            if (slot.MovableCount() > 0)
            {
                LinkedList <FieldCell> tempList = new LinkedList <FieldCell>();
                slot.GetCells(tempList);

                foreach (FieldCell cell in tempList)
                {
                    if (cell.IsBomb())
                    {
                        cell.AsBomb().Blow();
                    }
                    else if (cell.IsPlayer())
                    {
                        KillPlayer(cell.AsPlayer());
                    }
                }
            }

            SetFlame(bomb.player, cx, cy);
            return(true);
        }
Пример #4
0
        private void SetFlame(Player player, int cx, int cy)
        {
            FieldCellSlot slot  = GetSlot(cx, cy);
            FlameCell     flame = slot.GetFlame();

            if (flame != null && flame.player == player)
            {
                flame.RemoveFromField();
            }
            AddCell(new FlameCell(player, cx, cy));
        }
Пример #5
0
        public void UpdateSlot(float delta, FieldCellSlot slot)
        {
            slot.GetCells(m_tempCellsList);

            if (m_tempCellsList.Count > 0)
            {
                foreach (FieldCell cell in m_tempCellsList)
                {
                    cell.Update(delta);
                }
                m_tempCellsList.Clear();
            }
        }
Пример #6
0
        private int GetEmptySlots(FieldCellSlot[] array)
        {
            int count = 0;

            FieldCellSlot[] slots = cells.slots;
            for (int i = 0; i < slots.Length; ++i)
            {
                FieldCellSlot slot = slots[i];
                if (slot.IsEmpty())
                {
                    array[count++] = slot;
                }
            }

            return(count);
        }
        public FieldCellArray(int width, int height)
        {
            this.width = width;
            this.height = height;

            slots = new FieldCellSlot[width * height];

            int index = 0;
            for (int cy = 0; cy < height; ++cy)
            {
                for (int cx = 0; cx < width; ++cx)
                {
                    slots[index++] = new FieldCellSlot(cx, cy);
                }
            }
        }
Пример #8
0
        public FieldCellArray(int width, int height)
        {
            this.width  = width;
            this.height = height;

            slots = new FieldCellSlot[width * height];

            int index = 0;

            for (int cy = 0; cy < height; ++cy)
            {
                for (int cx = 0; cx < width; ++cx)
                {
                    slots[index++] = new FieldCellSlot(cx, cy);
                }
            }
        }
Пример #9
0
        //////////////////////////////////////////////////////////////////////////////

        #region Bombs

        public void SetBomb(Bomb bomb)
        {
            AddCell(bomb);

            FieldCellSlot slot    = GetSlot(bomb);
            PowerupCell   powerup = slot.GetPowerup();

            if (powerup != null)
            {
                powerup.RemoveFromField();
            }
            else
            {
                FlameCell flame = slot.GetFlame();
                if (flame != null)
                {
                    bomb.Blow();
                }
            }
        }
Пример #10
0
        public PowerupCell GetPowerup(int cx, int cy)
        {
            FieldCellSlot slot = GetSlot(cx, cy);

            return(slot != null?slot.GetPowerup() : null);
        }
Пример #11
0
        public BrickCell GetBrick(int cx, int cy)
        {
            FieldCellSlot slot = GetSlot(cx, cy);

            return(slot != null?slot.GetBrick() : null);
        }
Пример #12
0
        //////////////////////////////////////////////////////////////////////////////

        public SolidCell GetSolid(int cx, int cy)
        {
            FieldCellSlot slot = GetSlot(cx, cy);

            return(slot != null?slot.GetSolid() : null);
        }
Пример #13
0
        private int GetEmptySlots(FieldCellSlot[] array)
        {
            int count = 0;
            FieldCellSlot[] slots = cells.slots;
            for (int i = 0; i < slots.Length; ++i)
            {
                FieldCellSlot slot = slots[i];
                if (slot.IsEmpty())
                {
                    array[count++] = slot;
                }
            }

            return count;
        }
Пример #14
0
        public bool ContainsNoObstacle(int cx, int cy)
        {
            FieldCellSlot slot = GetSlot(cx, cy);

            return(slot != null && !slot.ContainsObstacle());
        }
Пример #15
0
        public bool HasNearObstacle(int dcx, int dcy)
        {
            FieldCellSlot slot = GetNearSlot(dcx, dcy);

            return(slot == null || slot.ContainsObstacle());
        }
Пример #16
0
        public bool HasNearObstacle(Direction dir)
        {
            FieldCellSlot slot = GetNearSlot(dir);

            return(slot == null || slot.ContainsObstacle());
        }
Пример #17
0
 private void ShuffleSlots(FieldCellSlot[] array, int size)
 {
     ArrayUtils.Shuffle(array, size);
 }
Пример #18
0
        public FlameCell GetFlame(int cx, int cy)
        {
            FieldCellSlot slot = GetSlot(cx, cy);

            return(slot != null?slot.GetFlame() : null);
        }
Пример #19
0
        public Bomb GetBomb(int cx, int cy)
        {
            FieldCellSlot slot = GetSlot(cx, cy);

            return(slot != null?slot.GetBomb() : null);
        }
Пример #20
0
        public void UpdateSlot(float delta, FieldCellSlot slot)
        {
            slot.GetCells(m_tempCellsList);

            if (m_tempCellsList.Count > 0)
            {
                foreach (FieldCell cell in m_tempCellsList)
                {
                    cell.Update(delta);
                }
                m_tempCellsList.Clear();
            }
        }
Пример #21
0
        public void DropPowerups(Player player)
        {
            FieldCellSlot[] slots = new FieldCellSlot[GetWidth() * GetHeight()];
            int slotsCount = GetEmptySlots(slots);
            if (slotsCount == 0)
            {
                return;
            }

            ShuffleSlots(slots, slotsCount);

            PowerupList powerups = player.powerups;
            int slotIndex = 0;
            for (int powerupIndex = 0; powerupIndex < Powerups.Count && slotIndex < slots.Length; ++powerupIndex)
            {
                int count = powerups.GetCount(powerupIndex);
                for (int i = 0; i < count && slotIndex < slots.Length; ++i)
                {
                    FieldCellSlot slot = slots[slotIndex++];
                    PowerupCell cell = new PowerupCell(powerupIndex, slot.cx, slot.cy);
                    AddCell(cell);
                }
            }
        }
Пример #22
0
        private bool CheckStillCollisions(MovableCell movable, FieldCellSlot slot)
        {
            if (slot != null)
            {
                FieldCell staticCell = slot.staticCell;
                if (staticCell != null)
                {
                    return CheckCollision(movable, staticCell);
                }

                bool handled = false;

                List<MovableCell> movableCells = slot.movableCells;
                for (int i = 0; i < movableCells.Count; ++i)
                {
                    MovableCell other = movableCells[i];
                    if (!other.IsMoving() && movable != other)
                    {
                        handled |= CheckCollision(movable, other);
                    }
                }

                return handled;
            }

            return false;
        }