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 void DestroyCandies(VisualChanges currentChanges)
 {
     if (candyBuffer.Count > 0)
     {
         List <Coordonate> emptySlots = new List <Coordonate>();
         foreach (Coordonate candy in candyBuffer)
         {
             emptySlots.Add(new Coordonate(candy.X, candy.Y));
         }
         candyBuffer = new List <Coordonate>();
         CandyFall(currentChanges, emptySlots);
     }
 }
Beispiel #5
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 #6
0
 public void CheckMoves(VisualChanges currentChanges)
 {
     for (int i = 0; i < Height; i++)
     {
         for (int j = 0; j < Width; j++)
         {
             if (slots[i, j] != null)
             {
                 if (slots[i, j].CurrentCandy != null)
                 {
                     slots[i, j].CurrentCandy.CheckDestroy(currentChanges, slots, Height, Width, this);
                 }
             }
         }
     }
 }
Beispiel #7
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 #8
0
        public void CheckDestroy(VisualChanges currentChanges, Slot[,] slots, int height, int width, Terrain terrain)
        {
            int x = ContainerSlot.CurrentCoordonate.X;
            int y = ContainerSlot.CurrentCoordonate.Y;

            int nrUp = 0, nrDown = 0, nrLeft = 0, nrRight = 0;

            nrUp    = CheckUp(slots, x, y);
            nrDown  = CheckDown(slots, x, y, height);
            nrLeft  = CheckLeft(slots, x, y);
            nrRight = CheckRight(slots, x, y, width);

            //nrUp = CheckDirection(Direction.Up, slots, x, y, width, height);
            //nrDown = CheckDirection(Direction.Down, slots, x, y, width, height);
            //nrLeft = CheckDirection(Direction.Left, slots, x, y, width, height);
            //nrRight = CheckDirection(Direction.Right, slots, x, y, width, height);

            DestroyCandies(currentChanges, slots, height, width, nrUp, nrDown, nrLeft, nrRight, terrain);
        }
Beispiel #9
0
        public VisualChanges Initialize()
        {
            VisualChanges currentChanges = new VisualChanges();

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    Slot up = null, down = null, left = null, right = null;
                    if (slots[i, j] != null)
                    {
                        up = GetUpSlot(i, j);
                        if (i < Height - 1)
                        {
                            if (slots[i + 1, j] != null)
                            {
                                down = slots[i + 1, j];
                            }
                        }
                        if (j > 0)
                        {
                            if (slots[i, j - 1] != null)
                            {
                                left = slots[i, j - 1];
                            }
                        }
                        if (j < Width - 1)
                        {
                            if (slots[i, j + 1] != null)
                            {
                                right = slots[i, j + 1];
                            }
                        }
                        slots[i, j].SetNearSlots(up, down, left, right);
                    }
                }
            }
            CandyFall(currentChanges);
            return(currentChanges);
        }
Beispiel #10
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);
             }
         }
     }
 }
Beispiel #11
0
 public void CandyFallDown(VisualChanges currentChanges, Slot down)
 {
     CandyFall(currentChanges);
     down.CandyFall(currentChanges);
 }