Exemplo n.º 1
0
        public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position start)
        {
            algorythm.From.X = ghost._position.X;
            algorythm.From.Y = ghost._position.Y;
            algorythm.To.X   = maze.BottomRightCorner.X;
            algorythm.To.Y   = maze.BottomRightCorner.Y;
            algorythm.Execute();
            List <Location> rightCornerBottom = algorythm.ResultPath;

            foreach (var i in rightCornerBottom)
            {
                if (ghost._position.X + 1 == i.X)
                {
                    ghost.direction = SidesToMove.Right;
                }

                else if (ghost._position.X - 1 == i.X)
                {
                    ghost.direction = SidesToMove.Left;
                }

                else if (ghost._position.Y - 1 == i.Y)
                {
                    ghost.direction = SidesToMove.Up;
                }

                else if (ghost._position.Y + 1 == i.Y)
                {
                    ghost.direction = SidesToMove.Down;
                }
            }
        }
Exemplo n.º 2
0
            public void GhostTest()
            {
                GhostA          ghostA            = new GhostA();
                IGpiA           gpiA              = ghostA;
                IGhost          ghost             = ghostA;
                PropertyInfo    addSupplyProperty = null;
                PassageCallback addSupplyPassage  = null;

                ghost.AddSupplyNoitfierEvent += (property, passage) =>
                {
                    addSupplyProperty = property;
                    addSupplyPassage  = passage;
                };
                IGpiB gPi = null;

                gpiA.GpiBs.Supply += (gpi) =>
                {
                    gPi = gpi;
                };

                SoulB soulB = new SoulB();

                addSupplyPassage(soulB);


                NUnit.Framework.Assert.AreEqual(soulB, gPi);
            }
Exemplo n.º 3
0
        private void _UpdateSetProperty(long entity_id, int property, byte[] buffer)
        {
            IGhost ghost = _FindGhost(entity_id);

            if (ghost == null)
            {
                return;
            }

            MemberMap    map  = _Protocol.GetMemberMap();
            PropertyInfo info = map.GetProperty(property);

            object    value    = _Serializer.Deserialize(buffer);
            object    instance = ghost.GetInstance();
            Type      type     = _InterfaceProvider.Find(info.DeclaringType);
            FieldInfo field    = type.GetField("_" + info.Name, BindingFlags.Instance | BindingFlags.Public);

            if (field != null)
            {
                object      filedValue = field.GetValue(instance);
                IAccessable updateable = filedValue as IAccessable;
                updateable.Set(value);


                PackageSetPropertyDone pkg = new PackageSetPropertyDone();
                pkg.EntityId = entity_id;
                pkg.Property = property;
                _Requester.Request(ClientToServerOpCode.UpdateProperty, pkg.ToBuffer(_Serializer));
            }
        }
Exemplo n.º 4
0
        public void Update()
        {
            List <long> ids = new List <long>();

            foreach (KeyValuePair <long, WeakReference <IGhost> > e in _Exists)
            {
                IGhost target = null;


                if (!e.Value.TryGetTarget(out target))
                {
                    ids.Add(e.Key);
                }
            }

            foreach (long id in ids)
            {
                _Exists.Remove(id);


                if (_Requester != null)
                {
                    PackageRelease data = new PackageRelease();
                    data.EntityId = id;
                    _Requester.Request(ClientToServerOpCode.Release, data.ToBuffer(_Serializer));
                }
            }
        }
Exemplo n.º 5
0
 public GhostNotifierHandler(IGhost ghost, IProtocol protocol, IGhostRequest requester, SoulNotifier notifierPassage)
 {
     this._Ghost      = ghost;
     _Protocol        = protocol;
     _Requester       = requester;
     _NotifierPassage = notifierPassage;
 }
Exemplo n.º 6
0
        public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position start)
        {
            algorythm.From.X = ghost._position.X;
            algorythm.From.Y = ghost._position.Y;
            algorythm.To.X   = start.X;
            algorythm.To.Y   = start.Y;

            algorythm.Execute();
            List <Location> route = algorythm.ResultPath;

            foreach (var step in route.ToList())
            {
                if (ghost._position.X + 1 == step.X)
                {
                    ghost.direction = SidesToMove.Right;
                }

                if (ghost._position.X - 1 == step.X)
                {
                    ghost.direction = SidesToMove.Left;
                }

                if (ghost._position.Y - 1 == step.Y)
                {
                    ghost.direction = SidesToMove.Up;
                }

                if (ghost._position.Y + 1 == step.Y)
                {
                    ghost.direction = SidesToMove.Down;
                }
            }
        }
Exemplo n.º 7
0
 public GhostMethodHandler(IGhost ghost, ReturnValueQueue return_value_queue, IProtocol protocol, Regulus.Remote.IGhostRequest requester)
 {
     _Ghost            = ghost;
     _ReturnValueQueue = return_value_queue;
     _Protocol         = protocol;
     _Requester        = requester;
 }
Exemplo n.º 8
0
        private void _SetReturnValue(long return_id, IGhost ghost)
        {
            IValue value = _ReturnValueQueue.PopReturnValue(return_id);

            if (value != null)
            {
                value.SetValue(ghost);
            }
        }
Exemplo n.º 9
0
        internal void Supply(IGhost ghost, long notifier_id)
        {
            PassageCallback passage = _FindSupply(notifier_id);

            if (passage != null)
            {
                passage(ghost);
            }
        }
Exemplo n.º 10
0
 public void Register(IGhost ghost)
 {
     var id = ghost.GetID();
     WeakReference instance;
     if(_Exists.TryGetValue(id, out instance) == false)
     {
         _Exists.Add(id, new WeakReference(ghost));
     }
 }
Exemplo n.º 11
0
        public void Register(IGhost ghost)
        {
            var id = ghost.GetID();

            if (_Exists.TryGetValue(id, out WeakReference instance) == false)
            {
                _Exists.Add(id, new WeakReference(ghost));
            }
        }
Exemplo n.º 12
0
        public void Register(IGhost ghost)
        {
            long id = ghost.GetID();
            WeakReference <IGhost> instance;

            if (_Exists.TryGetValue(id, out instance) == false)
            {
                _Exists.Add(id, new WeakReference <IGhost>(ghost));
            }
        }
Exemplo n.º 13
0
        public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position Start)
        {
            algorythm.From.X = ghost._position.X;
            algorythm.From.Y = ghost._position.Y;
            if (pacMan.direction == SidesToMove.Down)
            {
                algorythm.To.X = pacMan._position.X + 2;
                algorythm.To.Y = pacMan._position.Y - 2;
            }
            if (pacMan.direction == SidesToMove.Up)
            {
                algorythm.To.X = pacMan._position.X + 2;
                algorythm.To.Y = pacMan._position.Y + 2;
            }
            if (pacMan.direction == SidesToMove.Left)
            {
                algorythm.To.X = pacMan._position.X - 2;
                algorythm.To.Y = pacMan._position.Y - 2;
            }
            if (pacMan.direction == SidesToMove.Right)
            {
                algorythm.To.X = pacMan._position.X + 2;
                algorythm.To.Y = pacMan._position.Y - 2;
            }


            algorythm.Execute();
            List <Location> dir = algorythm.ResultPath;

            foreach (var i in dir.ToList())
            {
                if (i != null)
                {
                    if (ghost._position.X + 1 == i.X)
                    {
                        ghost.direction = SidesToMove.Right;
                    }

                    else if (ghost._position.X - 1 == i.X)
                    {
                        ghost.direction = SidesToMove.Left;
                    }

                    else if (ghost._position.Y - 1 == i.Y)
                    {
                        ghost.direction = SidesToMove.Up;
                    }

                    else if (ghost._position.Y + 1 == i.Y)
                    {
                        ghost.direction = SidesToMove.Down;
                    }
                }
            }
        }
Exemplo n.º 14
0
  //      private bool _is_frightened;

        public void init(IGhost gh, Grid gr)
        {
            ghosts = gh;
            _grid = gr;

            _scatter_time_table = new int []{7, 7, 5, 5};
            _chase_time_table = new int[] {20, 20, 20, 60000};
            _frightened_time = 10;

            reset();     
        }
Exemplo n.º 15
0
        private IObjectAccessible _GetAccesser(PackagePropertySoul data, IGhost owner)
        {
            MemberMap    map        = _Protocol.GetMemberMap();
            PropertyInfo info       = map.GetProperty(data.PropertyId);
            var          type       = _InterfaceProvider.Find(info.DeclaringType);
            var          fieldName  = _GetFieldName(info);
            FieldInfo    field      = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public);
            object       filedValue = field.GetValue(owner.GetInstance());

            return(filedValue as IObjectAccessible);
        }
Exemplo n.º 16
0
        public void ResetGhost()
        {
            if (mGhost == null)
            {
                return;
            }
            Rectangle rec = mGhost.Rectangle;

            rec.Inflate(10, 10);
            this.Invalidate(rec);
            mGhost = null;
        }
Exemplo n.º 17
0
        void IValue.SetValue(IGhost val)
        {
            if (_Empty == false)
            {
                throw new Exception("重覆的set value");
            }
            _Empty = false;

            _Value = (T)val;
            if (_OnValue != null)
            {
                _OnValue(_Value);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Resets the ghost.
        /// </summary>
        public void ResetGhost()
        {
            if (mGhost == null)
            {
                return;
            }
            Rectangle rec = mGhost.Rectangle;

            rec.Inflate(20, 20);
            //convert it to viewspace
            //rec = Rectangle.Round(WorldToView(rec));
            this.Invalidate(rec);
            mGhost = null;
        }
Exemplo n.º 19
0
        private void _LoadSoulCompile(int type_id, long entity_id, long return_id)
        {
            MemberMap map = _Protocol.GetMemberMap();

            Type type = map.GetInterface(type_id);

            IProvider provider = _QueryProvider(type);

            IGhost ghost = provider.Ready(entity_id);

            if (return_id != 0)
            {
                _ReturnValue(return_id, ghost);
            }
        }
Exemplo n.º 20
0
    public async Task UpdateIsRuledOutAsync(IGhost ghost, bool isRuledOut)
    {
        var localGhost = _ghosts.FirstOrDefault(localGhost => localGhost.Type == ghost.Type);

        if (localGhost is null)
        {
            return;
        }

        localGhost.IsRuledOut = isRuledOut;
        RecalculateGhostStates();
        if (OnUpdated is not null)
        {
            await OnUpdated.Invoke();
        }
    }
Exemplo n.º 21
0
        private void _InvokeEvent(long ghost_id, int event_id, long handler_id, byte[][] event_params)
        {
            IGhost ghost = _FindGhost(ghost_id);

            if (ghost == null)
            {
                return;
            }

            MemberMap map  = _Protocol.GetMemberMap();
            EventInfo info = map.GetEvent(event_id);



            object instance = ghost.GetInstance();
            Type   type     = instance.GetType();


            var       fieldName  = _GetFieldName(info);
            FieldInfo eventInfos = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public);
            object    fieldValue = eventInfos.GetValue(instance);

            if (fieldValue is GhostEventHandler)
            {
                GhostEventHandler fieldValueDelegate = fieldValue as GhostEventHandler;

                object[] pars = (from a in event_params select _Serializer.Deserialize(a)).ToArray();
                try
                {
                    fieldValueDelegate.Invoke(handler_id, pars);
                }
                catch (TargetInvocationException tie)
                {
                    Regulus.Utility.Log.Instance.WriteInfo(string.Format("Call event error in {0}:{1}. \n{2}", type.FullName, info.Name, tie.InnerException.ToString()));
                    throw tie;
                }
                catch (Exception e)
                {
                    Regulus.Utility.Log.Instance.WriteInfo(string.Format("Call event error in {0}:{1}.", type.FullName, info.Name));
                    throw e;
                }
            }
        }
Exemplo n.º 22
0
        private void _LoadSoul(int type_id, long id, bool return_type)
        {
            MemberMap map      = _Protocol.GetMemberMap();
            Type      type     = map.GetInterface(type_id);
            IProvider provider = _QueryProvider(type);
            IGhost    ghost    = _BuildGhost(type, id, return_type);

            ghost.CallMethodEvent  += new GhostMethodHandler(ghost, _ReturnValueQueue, _Protocol, _Requester).Run;
            ghost.AddEventEvent    += new GhostEventMoveHandler(ghost, _Protocol, _Requester).Add;
            ghost.RemoveEventEvent += new GhostEventMoveHandler(ghost, _Protocol, _Requester).Remove;



            provider.Add(ghost);

            if (ghost.IsReturnType())
            {
                _RegisterRelease(ghost);
            }
        }
Exemplo n.º 23
0
        private void _UnloadSoul(int type_id, long id, long passage_id)
        {
            MemberMap map      = _Protocol.GetMemberMap();
            Type      type     = map.GetInterface(type_id);
            IProvider provider = _QueryProvider(type);

            if (provider == null)
            {
                return;
            }

            IGhost ghost = provider.Ghosts.FirstOrDefault(g => g.GetID() == id);

            if (ghost == null)
            {
                return;
            }
            _NotifierPassage.Unsupply(ghost, passage_id);
            provider.Remove(id);
        }
Exemplo n.º 24
0
        private void _LoadSoulCompile(int type_id, long entity_id, long return_id, long passage_id)
        {
            MemberMap map = _Protocol.GetMemberMap();

            Type type = map.GetInterface(type_id);

            IProvider provider = _QueryProvider(type);

            if (provider != null)
            {
                IGhost ghost = provider.Ready(entity_id);

                _NotifierPassage.Supply(ghost, passage_id);

                _SetReturnValue(return_id, ghost);
            }
            else
            {
            }
        }
Exemplo n.º 25
0
        private IGhost _Add(T entity, IGhost ghost)
        {
            if (ghost.IsReturnType() == false)
            {
                lock (_Entitys)
                    _Entitys.Add(entity);
                if (_Supply != null)
                {
                    _Supply.Invoke(entity);
                }
            }
            else
            {
                _Returns.Add(new WeakReference(entity));
                if (_Return != null)
                {
                    _Return(entity);
                }
            }

            return(ghost);
        }
Exemplo n.º 26
0
        public IAction Build(ActionBuildType type, IShape shape)
        {
            int    index;
            IGhost ghost = Source.Ghost;

            switch (type)
            {
            case ActionBuildType.Select:
                index = Source.Shapes.IndexOf(shape);
                if (index == -1)
                {
                    return(null);
                }
                return(new SelectShape(index, SelectType.Select));

            case ActionBuildType.Deselect:
                index = Source.Shapes.IndexOf(ghost.Shape);
                return(new SelectShape(index, SelectType.Deselect));

            case ActionBuildType.AddNew:
                return(new NewShape(ghost.Shape.Data));

            case ActionBuildType.Motify:
                index = Source.Shapes.IndexOf(ghost.Shape);
                return(new ModifyShape(index, ghost.Shape.Data, ghost.OldData));

            case ActionBuildType.Delete:
                index = Source.Shapes.IndexOf(ghost.Shape);
                return(new DeleteShape(index));

            case ActionBuildType.CreateNewShape:
                return(new CreateGhost(shape.Data));

            case ActionBuildType.None:
            default:
                return(null);
            }
        }
Exemplo n.º 27
0
        private void ProcessOldGhost()
        {
            IGhost  ghost = Source.Ghost;
            IAction action;

            switch (ghost.State)
            {
            case GhostState.New:
                if (!ghost.Shape.Completed)
                {
                    Point[] pts = ghost.Shape.Data.Points;
                    if (pts != null &&
                        pts.Length >= ghost.Shape.MinPoints &&
                        pts.Length <= ghost.Shape.MaxPoints)
                    {
                        ghost.Shape.Complete();
                    }
                }
                if (ghost.Shape.Completed)
                {
                    action = Builder.Build(ActionBuildType.AddNew, ghost.Shape);
                    NewAction(action);
                }
                return;

            case GhostState.Modity:
                int index = Source.Shapes.IndexOf(ghost.Shape);
                action = Builder.Build(ActionBuildType.Motify, ghost.Shape);
                NewAction(action);
                return;

            case GhostState.NotAvailable:
            default:
                return;
            }
        }
Exemplo n.º 28
0
 public void remove(IGhost ghost)
 {
     ghost_list.Remove(ghost);
 }
Exemplo n.º 29
0
 public AStar(IGhost ghost, IPacMan pacMan, IMaze map)
 {
     this.ghost  = ghost;
     this.pacMan = pacMan;
     this.map    = map;
 }
Exemplo n.º 30
0
 private void _RegisterRelease(IGhost ghost)
 {
     _AutoRelease.Register(ghost);
 }
Exemplo n.º 31
0
        private void _SetReturnValue(Guid return_id, IGhost ghost)
        {
            var value = _ReturnValueQueue.PopReturnValue(return_id);

            value?.SetValue(ghost);
        }
Exemplo n.º 32
0
 public GhostInsideHouseEvent(IGhost ghost)
 {
     Ghost = ghost;
 }
Exemplo n.º 33
0
 public GhostStateChangedEvent(IGhost ghost, GhostState state)
 {
     Ghost = ghost;
     State = state;
 }
Exemplo n.º 34
0
 public void ResetGhost()
 {
     if (mGhost == null) return;
     Rectangle rec = mGhost.Rectangle;
     rec.Inflate(10, 10);
     this.Invalidate(rec);
     mGhost = null;
 }
Exemplo n.º 35
0
 /// <summary>
 /// Resets the ghost.
 /// </summary>
 public void ResetGhost()
 {
     if (mGhost == null) return;
     Rectangle rec = mGhost.Rectangle;
     rec.Inflate(20, 20);
     //convert it to viewspace
     //rec = Rectangle.Round(WorldToView(rec));
     this.Invalidate(rec);
     mGhost = null;
 }