示例#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);
        }
        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());
        }
 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);
        }
        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();
            }
        }
        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);
                }
            }
        }
        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;
        }