Beispiel #1
0
        public void DestroyCandies(VisualChanges currentChanges, Slot[,] slots, int height, int width, int nrUp, int nrDown, int nrLeft, int nrRight, Terrain terrain)
        {
            int x = ContainerSlot.CurrentCoordonate.X;
            int y = ContainerSlot.CurrentCoordonate.Y;

            List <Coordonate> destroyedCandies = new List <Coordonate>();

            if (nrUp + nrDown >= 2 || nrLeft + nrRight >= 2)
            {
                destroyedCandies.Add(slots[x, y].CurrentCandy.ContainerSlot.CurrentCoordonate);

                if (nrUp + nrDown >= 2)
                {
                    for (int i = x - 1; i >= 0; i--)
                    {
                        if (nrUp > 0)
                        {
                            destroyedCandies.Add(slots[i, y].CurrentCandy.ContainerSlot.CurrentCoordonate);
                            nrUp--;
                        }
                    }
                    for (int i = x + 1; i < height; i++)
                    {
                        if (nrDown > 0)
                        {
                            destroyedCandies.Add(slots[i, y].CurrentCandy.ContainerSlot.CurrentCoordonate);
                            nrDown--;
                        }
                    }
                }
                if (nrLeft + nrRight >= 2)
                {
                    for (int j = y - 1; j >= 0; j--)
                    {
                        if (nrLeft > 0)
                        {
                            destroyedCandies.Add(slots[x, j].CurrentCandy.ContainerSlot.CurrentCoordonate);
                            nrLeft--;
                        }
                    }
                    for (int j = y + 1; j < height; j++)
                    {
                        if (nrRight > 0)
                        {
                            destroyedCandies.Add(slots[x, j].CurrentCandy.ContainerSlot.CurrentCoordonate);
                            nrRight--;
                        }
                    }
                }

                DestroyMultipleCandiesChange change = new DestroyMultipleCandiesChange(destroyedCandies);
                currentChanges.Add(change);

                foreach (Coordonate coord in destroyedCandies)
                {
                    slots[coord.X, coord.Y].CurrentCandy.Destory(currentChanges, terrain);
                }
            }
        }
Beispiel #2
0
        //public void Destroy(VisualChanges currentChanges, List<Coordonate> dependencies)
        //{
        //    DestroyCandyChange change = new DestroyCandyChange(this.ContainerSlot.CurrentCoordonate,dependencies);
        //    currentChanges.Add(change);
        //    ContainerSlot.CurrentCandy = null;
        //}

        public void Destory(VisualChanges currentChanges, Terrain terrain)
        {
            DestroyCandyChange change = new DestroyCandyChange(this.ContainerSlot.CurrentCoordonate);

            currentChanges.Add(change);
            ContainerSlot.CurrentCandy = null;
            terrain.AddDestroyCandy(this);
        }
Beispiel #3
0
 public void CandyFall(VisualChanges currentChanges, List <Coordonate> destroyCoordonate)
 {
     foreach (Coordonate coord in destroyCoordonate)
     {
         slots[coord.X, coord.Y].CandyFall(currentChanges);
     }
     currentChanges.Add(new WaitChange(slots, Height, Width));
     CheckMoves(currentChanges);
     DestroyCandies(currentChanges);
 }
Beispiel #4
0
        public Candy(VisualChanges currentChanges, Slot currentSlot)
        {
            if (r == null)
            {
                r = new Random();
            }

            Type          = (CandyType)r.Next(numberOfTypesCandy);
            ContainerSlot = currentSlot;

            CreateCandyChange change = new CreateCandyChange(Type, this.ContainerSlot.CurrentCoordonate);

            currentChanges.Add(change);
        }
Beispiel #5
0
 public void CandyFall(VisualChanges currentChanges)
 {
     for (int i = 0; i < Height; i++)
     {
         for (int j = 0; j < Width; j++)
         {
             if (slots[i, j] != null)
             {
                 slots[i, j].CandyFall(currentChanges);
             }
         }
     }
     currentChanges.Add(new WaitChange(slots, Height, Width));
     CheckMoves(currentChanges);
     DestroyCandies(currentChanges);
 }
Beispiel #6
0
 public void CandyFall(VisualChanges currentChanges)
 {
     if (CurrentCandy == null)
     {
         if (slotUp == null)
         {
             CurrentCandy = new Candy(currentChanges, this);
         }
         else
         {
             if (slotUp.CurrentCandy == null)
             {
                 CandyFallDown(currentChanges, this);
             }
             else
             {
                 CurrentCandy = slotUp.CurrentCandy;
                 currentChanges.Add(new FallDownChange(slotUp.CurrentCoordonate, CurrentCoordonate));
                 slotUp.CurrentCandy = null;
                 slotUp.CandyFall(currentChanges);
             }
         }
     }
 }