Exemple #1
0
 public virtual void AddOperationShapeToLayer(ILayer <IPrimitive> layer)
 {
     if (__bound != null)
     {
         layer.Add(__bound);
     }
     Anchors.ForEach(a => a.AddToLayer(layer));
     ResizeHandles.ForEach(a => a.AddToLayer(layer));
 }
        public void ObjectAsBaseTest()
        {
            //TODO: Same for props and events
            //Better naming
            // Comments
            // out and ref params
            // rewrite test, one big with all features and lots of handlers

            // Create factory using plain object as base
            var factory = new AdaptiveFactory <object>();

            factory.ImplementMethods(m => m.Name == "Max").UsingSharedExecuter(GetMaxHandler);
            factory.ImplementMethods().UsingSharedExecuter(InitObjectAsBase, ExecObjectAsBase);
            factory.ImplementProperties(p => p.PropertyType == typeof(int)).UsingGetterAndSetter(InitProp, GetIntProp, SetIntProp);
            factory.ImplementEvents().UsingAdderAndRemover(InitEvent, AddEvent, RemoveEvent);
            //factory.AddMethodHandler<string>().ForAllMethods().WithInitializer(InitObjectAsBase).WithExecutor(ExecObjectAsBase);

            // Create implementation
            Type type = factory.Implement(typeof(ILayer));

            Assert.AreEqual(typeof(object), type.BaseType);
            Assert.AreNotEqual(typeof(object), type);

            // Verify same implementation next time
            Assert.AreSame(type, factory.Implement(typeof(ILayer)));

            // Create instance and call it
            ILayer layer = (ILayer)Activator.CreateInstance(type);

            Assert.AreEqual(3, layer.Add(1, 2));
            Assert.AreEqual(30, layer.Add(10, 20));

            var d = layer.GetOnly;

            layer.GetAndSet = 22;
            layer.Fire     += layer_Fire;
            layer.Fire     -= layer_Fire;
            // TODO: Impl setter, check box/unbox scenarios, generic setter/getter, generic TInfo

            int max = layer.Max(1, 3, 2);

            Assert.AreEqual(3, max);
        }
Exemple #3
0
        public bool Add(GameActorPosition gameActorPosition, bool collidesWithObstacles = false)
        {
            if (collidesWithObstacles)
            {
                IObjectLayer gameObjectLayer = GetLayer(LayerType.Object) as IObjectLayer;
                Debug.Assert(gameObjectLayer != null, "gameObjectLayer != null");
                Vector2         position = gameActorPosition.Position;
                GameActor       actor    = gameActorPosition.Actor;
                IPhysicalEntity physicalEntity;
                if (actor is IGameObject)
                {
                    physicalEntity          = (actor as IGameObject).PhysicalEntity;
                    physicalEntity.Position = position;
                }
                else if (actor is Tile)
                {
                    physicalEntity = (actor as Tile).GetPhysicalEntity(new Vector2I(gameActorPosition.Position));
                }
                else
                {
                    throw new ArgumentException("actor is unknown Type");
                }
                bool anyCollision = gameObjectLayer.GetPhysicalEntities().Any(x => x.CollidesWith(physicalEntity));
                if (anyCollision)
                {
                    return(false);
                }
                bool anyObstacleOnPosition =
                    GetObstaceLayers().Any(x => x.GetActorAt(new Vector2I(gameActorPosition.Position)) != null);
                if (anyObstacleOnPosition)
                {
                    return(false);
                }
            }

            ILayer <GameActor> layer = GetLayer(gameActorPosition.Layer);

            return(layer.Add(gameActorPosition));
        }
Exemple #4
0
 /// <summary>
 /// 添加到指定Layer中
 /// </summary>
 /// <param name="layer"></param>
 public virtual void AddToLayer(ILayer <IPrimitive> layer)
 {
     layer.Add(PrimaryPrimitive);
 }