Ejemplo n.º 1
0
        /// <summary>
        /// Verilen koordinatın çevre elemanlarının listesini verir
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public List<Cell> GetAroundItems(Cell cell)
        {
            double x = cell.Coordinate.X;
            double y = cell.Coordinate.Y;

            if (x < 0 || x >= RC_COUNT || y < 0 || y >= RC_COUNT)
                throw new Exception("Sınır dışı indis! (GetAroundItems() metodu)");

            Cell left = this.FindName("D" + x + "" + (y - 1)) as Cell;
            Cell left_top = this.FindName("D" + (x - 1) + "" + (x % 2 == 0 ? y - 1 : y)) as Cell;
            Cell left_bottom = this.FindName("D" + (x + 1) + "" + (x % 2 == 0 ? y - 1 : y)) as Cell;
            Cell right = this.FindName("D" + x + "" + (y + 1)) as Cell;
            Cell right_top = this.FindName("D" + (x - 1) + "" + (x % 2 == 0 ? y : y + 1)) as Cell;
            Cell right_bottom = this.FindName("D" + (x + 1) + "" + (x % 2 == 0 ? y : y + 1)) as Cell;

            // En yakın kenara göre yakın elemanlar listesi sırası ayarlanır
            List<Cell> around = new List<Cell>();
            switch (this.NearlyEdge(cell.Coordinate))
            {
                case Edge.Left:
                    {
                        if (left != null)
                            around.Add(left);
                        if (left_top != null)
                            around.Add(left_top);
                        if (left_bottom != null)
                            around.Add(left_bottom);
                        if (right_top != null)
                            around.Add(right_top);
                        if (right_bottom != null)
                            around.Add(right_bottom);
                        if (right != null)
                            around.Add(right);
                    }
                    break;
                case Edge.Top: ;
                    {
                        if (left_top != null)
                            around.Add(left_top);
                        if (right_top != null)
                            around.Add(right_top);
                        if (left != null)
                            around.Add(left);
                        if (right != null)
                            around.Add(right);
                        if (left_bottom != null)
                            around.Add(left_bottom);
                        if (right_bottom != null)
                            around.Add(right_bottom);
                    }
                    break;
                case Edge.Right: ;
                    {
                        if (right != null)
                            around.Add(right);
                        if (right_top != null)
                            around.Add(right_top);
                        if (right_bottom != null)
                            around.Add(right_bottom);
                        if (left_top != null)
                            around.Add(left_top);
                        if (left_bottom != null)
                            around.Add(left_bottom);
                        if (left != null)
                            around.Add(left);
                    }
                    break;
                case Edge.Bottom: ;
                    {
                        if (left_bottom != null)
                            around.Add(left_bottom);
                        if (right_bottom != null)
                            around.Add(right_bottom);
                        if (left != null)
                            around.Add(left);
                        if (right != null)
                            around.Add(right);
                        if (left_top != null)
                            around.Add(left_top);
                        if (right_top != null)
                            around.Add(right_top);
                    }
                    break;
            }

            return around;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Eleman kenarda mı?
 /// </summary>
 /// <param name="cell"></param>
 /// <returns></returns>
 private bool IsOnEdge(Cell cell)
 {
     return (cell.Coordinate.X == 0 || cell.Coordinate.X == RC_COUNT - 1 || cell.Coordinate.Y == 0 || cell.Coordinate.Y == RC_COUNT - 1);
 }