Exemple #1
0
 /// <summary>
 /// Добавляет значение-ключ
 /// </summary>
 /// <param name="key">Ключ.</param>
 /// <param name="value">Ассоциация.</param>
 public void Add(int x, int y)
 {
     try
     {
         GridObject tmp = new GridObject();
         tmp.SetCoordinate(x, y);
         objectTable.Add(tmp.Clone(), tmp.Clone());
     }
     catch
     {
     }
 }
Exemple #2
0
        /// <summary>
        /// Удаляет сущность.
        /// </summary>
        /// <param name="key">Ключ, идентифицирующий значение.</param>
        /// <returns>True если удалено.</returns>
        public bool Remove(int x, int y)
        {
            GridObject tmp = new GridObject();

            tmp.SetCoordinate(x, y);
            foreach (GridObject cur in this.objectTable.Keys)
            {
                if (tmp.Equals(cur as object))
                {
                    return(objectTable.Remove(cur));
                }
            }
            return(false);
        }
Exemple #3
0
 public bool ContainsKey(int x, int y)
 {
     using (GridObject tmp = new GridObject())
     {
         tmp.SetCoordinate(x, y);
         foreach (GridObject cur in this.objectTable.Keys)
         {
             if (tmp.Equals(cur as object))
             {
                 return(true);
             }
         }
         return(false);
     }
 }
Exemple #4
0
        /// <summary>
        /// ќбход сетки
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="pr"></param>
        private void GridTraversing(int x, int y, Presenter pr)
        {
            Stack <GridObject> stack = new Stack <GridObject>();

            GridObject tmp = new GridObject(x, y);

            stack.Push(tmp);

            Condition condition = new Condition(Mines.ContainsKey);

            while (!(stack.Count == 0))
            {
                tmp = stack.Pop();

                int num = CertainCondition(tmp.XCoordinate, tmp.YCoordinate, condition);

                hasAccessed.Add(tmp.XCoordinate, tmp.YCoordinate);

                if (num == 0)
                {
                    pr(tmp.XCoordinate, tmp.YCoordinate, num);

                    for (int i = tmp.XCoordinate - 1; i <= tmp.XCoordinate + 1; i++)
                    {
                        for (int j = tmp.YCoordinate - 1; j <= tmp.YCoordinate + 1; j++)
                        {
                            if (i >= 0 && i < Lines && j >= 0 && j < Columns && !hasAccessed.ContainsKey(i, j) && !Flags.ContainsKey(i, j))
                            {
                                pr(i, j, num);

                                hasAccessed.Add(i, j);

                                stack.Push(new GridObject(i, j));
                            }
                        }
                    }
                }
                else
                {
                    pr(tmp.XCoordinate, tmp.YCoordinate, num);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// получает значение в  (x,y).
        /// </summary>
        /// <param name="index">Координаты.</param>
        /// <returns>Значение.</returns>
        public GridObject this[int x, int y]
        {
            get
            {
                using (GridObject tmp = new GridObject())
                {
                    tmp.SetCoordinate(x, y);

                    foreach (GridObject cur in this.objectTable.Keys)
                    {
                        if (tmp.Equals(cur as object))
                        {
                            return(objectTable[cur]);
                        }
                    }
                    return(null);
                }
            }
        }