Exemplo n.º 1
0
 /// <summary>
 /// Получить активный объект по идентификатору
 /// </summary>
 /// <param name="Id">Идентификатор</param>
 /// <returns>Объект</returns>
 public MapActiveObjectState GetActiveObjectById(Guid Id)
 {
     if (Id == null)
     {
         throw new ArgumentNullException("Id", "Id cannot be null");
     }
     if (!ActiveObjects.ContainsKey(Id))
     {
         throw new ArgumentException("ActiveObject", "This ActiveObject not found");
     }
     return(ActiveObjects[Id]);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Добавить новый объект на карту
        /// </summary>
        /// <param name="ActiveObjectState">Активный объект</param>
        /// <param name="Position">Координаты левой верхней точки</param>
        /// <param name="Id">Идентификатор (для десериализации)</param>
        /// <returns>Получилось ли добавить</returns>
        public bool AddActiveObject(MapActiveObjectState ActiveObjectState, Guid Id)
        {
            if (ActiveObjectState == null)
            {
                throw new ArgumentNullException("ActiveObjectState", "ActiveObjectState cannot be null");
            }

            if (ActiveObjects.ContainsKey(Id))
            {
                return(false);
            }

            if (ActiveObjectState.Position.Level >= this.LevelsCount)
            {
                throw new ArgumentOutOfRangeException("Position.Level", "Level cannot be out of map");
            }

            if ((ActiveObjectState.Position.X + ActiveObjectState.Tile.Size.Width >= this.Size.Width) ||
                (ActiveObjectState.Position.Y + ActiveObjectState.Tile.Size.Height >= this.Size.Height))
            {
                throw new ArgumentOutOfRangeException("Position", "Position cannot be out of map");
            }

            if (!CheckPlaceForActiveObject(ActiveObjectState.ActiveObject, ActiveObjectState.Position))
            {
                throw new ArgumentException("ActiveObject", "ActiveObject cannot be located to this Position");
            }

            ActiveObjectState.Destroying += (sender, args) => { OnActiveObjectDestroying(args.ActiveObject); };
            ActiveObjectState.Destroyed  += (sender, args) => { OnActiveObjectDestroyed(args.ActiveObject); };
            this.ActiveObjects.Add(Id, ActiveObjectState);

            AttachActiveObject(ActiveObjectState, ActiveObjectState.Position);

            return(true);
        }