Пример #1
0
        public void RegisterComponent(IGameComponent component)
        {
            var viewComp = component as ChangeColorOnCollisionSystemView;

            if (viewComp)
            {
                viewComp.NewColorVector
                .Subscribe(vec => _color = vec)
                .AddTo(viewComp);
            }
            var changeColorComp = component as ChangeColorOnCollisionComponent;

            if (changeColorComp)
            {
                changeColorComp
                .OnCollisionStayAsObservable()
                .Subscribe(collision => ChangeColor(changeColorComp))
                .AddTo(changeColorComp);

                changeColorComp
                .OnCollisionExitAsObservable()
                .Subscribe(collision => ChangeColorBack(changeColorComp))
                .AddTo(changeColorComp);
            }
        }
        public override void OnDiffComponent(IGameEntity leftEntity, IGameComponent leftComponent,
                                             IGameEntity rightEntity, IGameComponent rightComponent)
        {
            IGameEntity localEntity;

            localEntityMap.TryGetValue(leftEntity.EntityKey, out localEntity);
            if (localEntity == null)
            {
                return;
            }
            // entity存在,但是不是playback
            var localComponent = localEntity.GetComponent(leftComponent.GetComponentId());

            if (localComponent != null)
            {
                var local = localComponent as IInterpolatableComponent;
                if (local.IsInterpolateEveryFrame())
                {
                    playBackInfos.Add(new PlayBackInfo(localComponent, leftComponent, rightComponent));
                }
                try
                {
                    info.BeginProfileOnlyEnableProfile();
                    local.Interpolate(leftComponent, rightComponent, interpolationInfo);
                }
                finally
                {
                    info.EndProfileOnlyEnableProfile();
                }
            }
        }
        public IGameComponent GetChildByName(string name)
        {
            if (name == null)
            {
                return(null);
            }
            foreach (var component in _childComponents)
            {
                if (component.Name == name)
                {
                    return(component);
                }
            }
            IGameComponent g = null;

            foreach (var component in _childComponents)
            {
                g = (component as IGameComponentContainer)?.GetChildByName(name);
                if (g != null)
                {
                    break;
                }
            }
            return(g);
        }
Пример #4
0
            public override void Run()
            {
                Canvas canvas = null;

                while (_running)
                {
                    //if (_drawing)
                    //{
                    try
                    {
                        canvas = _surfaceHolder.LockCanvas(null);
                        if (canvas == null)
                        {
                            continue;
                        }

                        canvas.DrawColor(Color.Transparent, PorterDuff.Mode.Clear);
                        canvas.DrawBitmap(_fieldBitmap, 0, 0, null);
                        for (int idx = 0; idx < _drawableObjs.Count; idx++)
                        {
                            _drawItem = _drawableObjs[idx];
                            if (_drawItem.CurPosition == null)
                            {
                                continue;
                            }
                            IDrawableComponent drawable = _drawItem as IDrawableComponent;
                            if (drawable == null)
                            {
                                throw new InvalidCastException($"The drawable obj must be inherited from {nameof(IDrawableComponent)}");
                            }
                            canvas.DrawBitmap(drawable.Bitmap, _drawItem.CurPosition.X, _drawItem.CurPosition.Y, null);

                            //var list = _drawableObjs[listIdx];
                            //for (int drawObjIdx = 0; drawObjIdx < list.Count; drawObjIdx++)
                            //{
                            //    _drawItem = list[drawObjIdx];
                            //    if (_drawItem.CurPosition == null) continue;
                            //    IDrawableComponent drawable = _drawItem as IDrawableComponent;
                            //    if (drawable == null)
                            //        throw new InvalidCastException(
                            //            $"The drawable obj must be inherited from {nameof(IDrawableComponent)}");
                            //    canvas.DrawBitmap(drawable.Bitmap, _drawItem.CurPosition.X, _drawItem.CurPosition.Y,
                            //        null);
                            //}
                        }
                    }
                    catch (System.Exception e)
                    {
                        throw new System.Exception($"There is exception in Canvas field. {e}");
                    }
                    finally
                    {
                        if (canvas != null)
                        {
                            _surfaceHolder.UnlockCanvasAndPost(canvas);
                        }
                    }
                    //}
                }
            }
Пример #5
0
        public void Dispose()
        {
            lock (this)
            {
                IGameComponent[] array = new IGameComponent[this.Components.Count];
                this.Components.CopyTo(array, 0);
                for (int i = 0; i < array.Length; i++)
                {
                    IDisposable disposable = array[i] as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                IDisposable disposable2 = this.graphicsDeviceManager as IDisposable;
                if (disposable2 != null)
                {
                    disposable2.Dispose();
                }
                this.UnhookDeviceEvents();

                if (this.Disposed != null)
                {
                    this.Disposed(this, EventArgs.Empty);
                }
            }
        }
Пример #6
0
        public static ComponentWrapper Allocate(IGameComponent component)
        {
            var rc = ObjectAllocatorHolder <ComponentWrapper> .Allocate();

            rc._component = component;
            return(rc);
        }
Пример #7
0
		/// <summary>
		/// Adds the specified key and value to the dictionary.
		/// </summary>
		/// <param name="key">The key of the element to add.</param>
		/// <param name="value">The value of the element to add. The value can be null for reference types.</param>
		/// <exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.</exception>
		/// <exception cref="T:System.ArgumentException">An element with the same key already exists in the <see cref="T:System.Collections.Generic.Dictionary`2"/>.</exception>
		public override void Add(string key, IGameComponent value)
		{
			base.Add(key, value);

			if (value is KarelComponent)
				((KarelComponent)value).Parent = this;
		}
Пример #8
0
        public GameOverState(IAnarkanoidGame arkanoidGame, IKeysConfiguration keysConfiguration) : base(arkanoidGame, keysConfiguration)
        {
            _text = new ShowText(Configuration, new Size(Configuration.ScreenSize.Width, Configuration.ScreenSize.Height));
            AnarkanoidGame.ComponentManager.AddText(_text, DIE_TEXT);

            CommandPerKey.Add(Keys.Left, CommandsFactory.GetActionCommand(NewMatch));
        }
Пример #9
0
        public override void OnDiffComponent(IGameEntity leftEntity, IGameComponent leftComponent, IGameEntity rightEntity, IGameComponent rightComponent)
        {
            IGameEntity localEntity;

            _localEntityMap.TryGetValue(leftEntity.EntityKey, out localEntity);
            if (localEntity != null) // entity存在,但是不是playback
            {
                var localComponent = localEntity.GetComponent(leftComponent.GetComponentId());
                if (localComponent != null)
                {
                    var local = localComponent as IInterpolatableComponent;
                    if (local.IsInterpolateEveryFrame())
                    {
                        _playBackInfos.Add(new PlayBackInfo(localComponent, leftComponent, rightComponent));
                    }
                    try
                    {
                        _info.BeginProfile();
                        local.Interpolate(leftComponent, rightComponent,
                                          _interpolationInfo);
                    }
                    finally
                    {
                        _info.EndProfile();
                    }
                }
                else
                {
                    //_logger.WarnFormat("component is null while playback {0}:{1}", localEntity.EntityKey, leftComponent.GetComponentId());
                }
            }
        }
Пример #10
0
 public void RegisterComponent(IGameComponent component)
 {
     RegisterComponent(component as RoomRotationWallComponent);
     RegisterComponent(component as RotatableRoomComponent);
     RegisterComponent(component as RoomRotationConfig);
     RegisterComponent(component as GameControlHelper);
 }
Пример #11
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         lock (this)
         {
             IGameComponent[] array = new IGameComponent[this.gameComponents.Count];
             this.gameComponents.CopyTo(array, 0);
             for (int i = 0; i < array.Length; i++)
             {
                 IDisposable disposable = array[i] as IDisposable;
                 if (disposable != null)
                 {
                     disposable.Dispose();
                 }
             }
             IDisposable graphicsDeviceManager = this.graphicsDeviceManager as IDisposable;
             if (graphicsDeviceManager != null)
             {
                 graphicsDeviceManager.Dispose();
             }
             this.UnhookDeviceEvents();
             if (this.Disposed != null)
             {
                 this.Disposed(this, EventArgs.Empty);
             }
         }
     }
 }
Пример #12
0
 public void RegisterComponent(IGameComponent component)
 {
     RegisterComponent(component as UISystemConfig);
     RegisterComponent(component as UiTriggerComponent);
     RegisterComponent(component as HealthComponent);
     RegisterComponent(component as PointsHelper);
 }
Пример #13
0
        public static void Load(string pluginName, bool needsInit)
        {
            try {
                string   dir   = Path.Combine(Program.AppDirectory, "plugins");
                string   path  = Path.Combine(dir, pluginName + ".dll");
                Assembly lib   = Assembly.LoadFrom(path);
                Type[]   types = lib.GetTypes();

                for (int i = 0; i < types.Length; i++)
                {
                    if (!IsPlugin(types[i]))
                    {
                        continue;
                    }

                    IGameComponent plugin = (IGameComponent)Activator.CreateInstance(types[i]);
                    if (needsInit)
                    {
                        plugin.Init(game);
                        plugin.Ready(game);
                    }

                    if (plugin == null)
                    {
                        throw new InvalidOperationException("Type " + types[i].Name + " returned null instance");
                    }
                    game.Components.Add(plugin);
                }
            } catch (Exception ex) {
                ErrorHandler.LogError("PluginLoader.Load() - " + pluginName, ex);
            }
        }
Пример #14
0
        void Load(string path, bool needsInit)
        {
            try {
                Assembly lib   = Assembly.LoadFrom(path);
                Type[]   types = lib.GetTypes();

                for (int i = 0; i < types.Length; i++)
                {
                    if (!IsPlugin(types[i]))
                    {
                        continue;
                    }

                    IGameComponent plugin = (IGameComponent)Activator.CreateInstance(types[i]);
                    if (needsInit)
                    {
                        plugin.Init(game);
                        plugin.Ready(game);
                    }

                    if (plugin == null)
                    {
                        throw new InvalidOperationException("Type " + types[i].Name + " returned null instance");
                    }
                    game.Components.Add(plugin);
                }
            } catch (Exception ex) {
                path = Path.GetFileNameWithoutExtension(path);
                ErrorHandler.LogError("PluginLoader.Load() - " + path, ex);
            }
        }
Пример #15
0
        public IGameComponent GetChildByType(Type type)
        {
            if (type == null || !type.IsSubclassOf(typeof(IGameComponent)))
            {
                return(null);
            }
            foreach (var component in _childComponents)
            {
                if (component.GetType() == type)
                {
                    return(component);
                }
            }
            IGameComponent g = null;

            foreach (var component in _childComponents)
            {
                g = (component as IGameComponentContainer)?.GetChildByType(type);
                if (g != null)
                {
                    break;
                }
            }
            return(g);
        }
Пример #16
0
        public void RegisterComponent(IGameComponent component)
        {
            var comp = component as EnemyMovementComponent;

            if (comp)
            {
                comp
                .OnCollisionStayAsObservable()
                .Where(collision => collision.gameObject.tag == _wallTag)
                .Subscribe(collision => comp.IsOnWall = true)
                .AddTo(comp);
                comp
                .OnCollisionExitAsObservable()
                .Where(collision => collision.gameObject.tag == _wallTag)
                .Subscribe(collision => comp.IsOnWall = false)
                .AddTo(comp);

                comp
                .FixedUpdateAsObservable()
                .Where(unit => comp.IsActive && comp.IsOnWall)
                .Subscribe(unit => MoveEnemy(comp))
                .AddTo(comp);
                return;
            }
            var config = component as EnemyMovementConfig;

            if (config)
            {
                config
                .Speed
                .Subscribe(f => _speed = f)
                .AddTo(config);
            }
        }
 public bool IsMouseOwner(IGameComponent component)
 {
     if (MouseOwner == null || MouseOwner == component)
     {
         return(true);
     }
     return(false);
 }
Пример #18
0
 public GameObject(IGameComponent inputComponent, IGameComponent physicComponent,
                   IGameComponent logicComponent, IGameComponent graphicComponent)
 {
     _inputComponent   = inputComponent;
     _physicComponent  = physicComponent;
     _logicComponent   = logicComponent;
     _graphicComponent = graphicComponent;
 }
Пример #19
0
 protected void CreateGameComponent(int componentId)
 {
     if (_component != null)
     {
         GameComponentInfo.Instance.Free(_component);
     }
     _component = GameComponentInfo.Instance.Allocate(componentId);
 }
Пример #20
0
        private Task OnOwnerDeleting(IGameComponent arg)
        {
            this.commandRequestSubscription.Unsubscribe();
            IPlayer player = (IPlayer)arg;

            player.Deleting -= this.OnOwnerDeleting;
            return(Task.FromResult(0));
        }
Пример #21
0
 public override void Add(IGameComponent component)
 {
     base.Add(component);
     if (CurrentComponentIndex < 0 && Components.Count > 0)
     {
         CurrentComponentIndex = 0;
     }
 }
Пример #22
0
        public void SyncTo(IGameComponent characterBoneComponent)
        {
            var boneComponent = characterBoneComponent as CharacterBoneComponent;

            _followRot.SyncTo(boneComponent);
            _weaponRot.SyncTo(boneComponent);
            _playerIkController.SyncTo(boneComponent);
        }
Пример #23
0
        public override void OnDiffComponent(IGameEntity leftEntity, IGameComponent leftComponent,
                                             IGameEntity rightEntity, IGameComponent rightComponent)
        {
            _logger.DebugFormat("rewind component field {0}:{1}", leftEntity.EntityKey, rightComponent.GetType());
            var left = leftComponent as IRewindableComponent;

            left.RewindTo(rightComponent);
        }
Пример #24
0
 public void CreateLastGameComponent(int componentId)
 {
     if (_lastComponent != null)
     {
         GameComponentInfo.Instance.Free(_lastComponent);
     }
     _lastComponent = GameComponentInfo.Instance.Allocate(componentId);
 }
Пример #25
0
 public void Add(IGameComponent component, Texture2D texture)
 {
     if (!_spritesByComponent.ContainsKey(component))
     {
         var spriteBatch = new SpriteBatch(_graphicsDevice);
         _spritesByComponent.Add(component, new Tuple <Texture2D, SpriteBatch>(texture, spriteBatch));
     }
 }
Пример #26
0
 public override void Remove(IGameComponent component)
 {
     base.Remove(component);
     if (CurrentComponentIndex >= Components.Count)
     {
         CurrentComponentIndex = Components.Count - 1;
     }
 }
Пример #27
0
 public static void AddComponentReadyInvoker(IGameComponent invoker)
 {
     ComponentReadyInvokers.Add(invoker);
     foreach (var listener in ComponentReadyListeners)
     {
         invoker.AddComponentReadyListener(listener);
     }
 }
Пример #28
0
        /// <summary>
        /// Unregisters the given GameComponent, causing it to no longer be active.
        /// </summary>
        public void RemoveGlobalComponent(IGameComponent Component)
        {
            bool result = _Game.Components.Remove(Component);

            if (!result)
            {
                throw new ArgumentException("The given component was not registered.");
            }
        }
Пример #29
0
 private void InitializeExistingComponents()
 {
     IGameComponent[] array = new IGameComponent[this.Components.Count];
     this.Components.CopyTo(array, 0);
     foreach (IGameComponent gameComponent in array)
     {
         gameComponent.Initialize();
     }
 }
Пример #30
0
        public void PickUp(IGameComponent item)
        {
            if (item.Type == GameComponentType.Apple)
            {
                Apples.Remove((IFoodComponent)item);
            }

            _drawableObjs.Remove(item);
        }
Пример #31
0
        public static DeleteComponentPatch Allocate(IGameComponent comp)
        {
            var rc = ObjectAllocatorHolder <DeleteComponentPatch> .Allocate();

            rc.CreateGameComponent(comp.GetComponentId());
            // ReSharper disable once PossibleNullReferenceException
            (rc.Component as INetworkObject).CopyFrom(comp);
            return(rc);
        }
Пример #32
0
        public IGameComponent AddComponent(IGameComponent component)
        {
            if (HasComponent(component))
                throw new InvalidOperationException("Cannot add the same component more than once.");

            Components.Add(component);
            component.Enable();
            return component; // var comp = someState.AddComponent(new SomeComponent());
        }
        /// <summary>
        /// Adds a new component to the screen and in case its a 
        /// ISoundableGameComponent we'll add it to a dedicated inner list
        /// </summary>
        /// <param name="i_Component">The new component we want to add 
        /// to the screen</param>
        public override void Add(IGameComponent i_Component)
        {
            base.Add(i_Component);

            ISoundableGameComponent component = i_Component as ISoundableGameComponent;

            if (component != null)
            {
                component.PlayActionSoundEvent += new PlayActionSoundDelegate(Component_PlayActionSoundEvent);
            }
        }
Пример #34
0
        public void RemoveGameComponent(IGameComponent component)
        {
            var res = Components.FirstOrDefault( c =>
            {
                var comp = c as GameComponentWrapper;
                if (comp == null)
                    return false;

                return comp.Component == component;
            });

            if (res == null)
                return;

            Components.Remove(res);
        }
Пример #35
0
        /// <summary>
        /// Adds a new component to the screen. 
        /// In case it's a MenuItem, we'll save it in a dedicated list in
        /// addition to the parent list
        /// </summary>
        /// <param name="i_Component">The component we want to add to the screen</param>
        public override void Add(IGameComponent i_Component)
        {
            base.Add(i_Component);

            MenuItem item = i_Component as MenuItem;

            // Adding item and registering item selected event
            if (item != null)
            {
                m_MenuItems.Add(item);
                setItemPosition(m_MenuItems.Count - 1);
                item.Selected += new MenuItemSelectedEventHandler(item_Selected);

                if (m_MenuItems.Count == 1)
                {
                    m_MenuItems[0].IsSelected = true;
                    m_CurrentMenuItem = 0;
                }
            }
        }
Пример #36
0
        private void objectCollision()
        {
            Player player = game.currentLevel.getPlayer();
            IGameComponent[] copy = new IGameComponent[game.Components.Count]; //component list is coppied to avoid concurrent modification exceptions when a collission is detected. i.e. adding explosion effect etc.
            game.Components.CopyTo(copy, 0);

            foreach (GameComponent component in copy)
            {
                ICollidable component3D = component as ICollidable; //tests if component implements ICollidable and thus is collidable
                if (component3D != null)
                {
                    Player componentPlayer = component3D as Player; //makes sure the component being looked at is not the player
                    if (componentPlayer == null)
                    {
                        foreach (ModelMesh mesh in player.getModel().Meshes)
                        {
                            foreach (ModelMesh currentMesh in component3D.getModel().Meshes)
                            {
                                BoundingSphere otherBoundingSphere = currentMesh.BoundingSphere; // set the bounding sphere to being the mesh's bounding sphere.
                                Planet planet = component3D as Planet; // test if the component being checked is a planet.
                                if (planet != null)
                                {
                                    otherBoundingSphere.Radius += 1; //if it is, its bounding sphere needs to be above the surface of the planet.
                                }
                                otherBoundingSphere = otherBoundingSphere.Transform(currentMesh.ParentBone.Transform * Matrix.CreateScale(component3D.getScale(), component3D.getScale(), component3D.getScale()) * Matrix.CreateTranslation(component3D.getPosition()));

                                BoundingSphere playerBoundingSphere = mesh.BoundingSphere; // find the players bounding sphere for each mesh.
                                playerBoundingSphere = playerBoundingSphere.Transform(mesh.ParentBone.Transform * Matrix.CreateScale(player.getScale(), player.getScale(), player.getScale()) * Matrix.CreateTranslation(player.getPosition()));

                                if (playerBoundingSphere.Intersects(otherBoundingSphere) && component3D.isAlive())
                                {
                                    component3D.collision(player);
                                    player.collision(component3D);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #37
0
 public void BindGameComponent( IGameComponent gameComponent )
 {
     this.Components.Add( gameComponent );
 }
Пример #38
0
 public void BindGameComponent(IGameComponent gameComponent, Type serviceInterface)
 {
     this.BindGameComponent( gameComponent );
     this.Services.AddService( serviceInterface, gameComponent );
 }
Пример #39
0
		/// <summary>
		/// Gets the value associated with the specified key.
		/// </summary>
		/// <returns>
		/// true if the <see cref="T:System.Collections.Generic.Dictionary`2"/> contains an element with the specified key; otherwise, false.
		/// </returns>
		/// <param name="key">The key of the value to get.</param><param name="value">When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the <paramref name="value"/> parameter. This parameter is passed uninitialized.</param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.</exception>
		public bool TryGetValue(string key, out IGameComponent value)
		{
			return _children.TryGetValue(key, out value);
		}
Пример #40
0
        /// <summary>
        /// コンポーネントを追加する
        /// Loadedがtrueの場合、Game.Componentsに追加で登録される
        /// Loadedがfalseの場合、RegistInitialiseComponentメソッドが実行されるまで登録されない
        /// </summary>
        /// <param name="component"></param>
        public void AddComponent(IGameComponent component)
        {
            GameComponent baseComponent = component as GameComponent;
            if (baseComponent != null)
            {
                _baseComponents.Add(baseComponent);
            }

            DrawableGameComponent drawableComponent = component as DrawableGameComponent;
            if (drawableComponent != null)
            {
                _drawableComponents.Add(drawableComponent);
            }

            // シーン読み込み後に追加されたコンポーネントを登録
            if (Loaded)
            {
                Game.Components.Add(component);
            }
        }
Пример #41
0
		/// <summary>
		/// Adds a key/value pair to the <see cref="T:System.Collections.Concurrent.ConcurrentDictionary`2"/> if the key does not already exist.
		/// </summary>
		/// <returns>
		/// The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary.
		/// </returns>
		/// <param name="key">The key of the element to add.</param><param name="value">the value to be added, if the key does not already exist</param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is a null reference (Nothing in Visual Basic).</exception><exception cref="T:System.OverflowException">The dictionary contains too many elements.</exception>
		public virtual IGameComponent GetOrAdd(string key, IGameComponent value)
		{
			return _children.GetOrAdd(key, value);
		}
Пример #42
0
 private Task OnOwnerDeleting(IGameComponent arg)
 {
     this.commandRequestSubscription.Unsubscribe();
     IPlayer player = (IPlayer)arg;
     player.Deleting -= this.OnOwnerDeleting;
     return Task.FromResult(0);
 }
Пример #43
0
 public void AddGameComponent(IGameComponent component)
 {
     Components.Add(new GameComponentWrapper(component, this));
     component.Initialize();
 }
Пример #44
0
        /// <summary>
        /// Event handler to disconnect the socket when the palyer is being deleted.
        /// </summary>
        /// <param name="component">The component being deleted.</param>
        /// <returns>Returns an awaitable Task</returns>
        private Task DisconnectPlayer(IGameComponent component)
        {
            if (this.outboundMessage != null)
            {
                this.outboundMessage.Unsubscribe();
            }

            component.Deleting -= this.DisconnectPlayer;

            this.socket.Shutdown(SocketShutdown.Both);
            this.socket = null;

            var handler = this.Disconnected;
            if (handler == null)
            {
                return Task.FromResult(0);
            }

            handler(this, new ConnectionClosedArgs(this.player, this));
            return Task.FromResult(0);
        }
Пример #45
0
 public void GiveGomponent(IGameComponent component)
 {
     _components.Add(component);
 }
Пример #46
0
 public ChatMessageBase(string message, IGameComponent sender)
 {
     this.Content = message;
     this.Sender = sender;
 }
Пример #47
0
		/// <summary>
		/// Adds a key/value pair to the <see cref="T:System.Collections.Concurrent.ConcurrentDictionary`2"/> if the key does not already exist, or updates a key/value pair in the <see cref="T:System.Collections.Concurrent.ConcurrentDictionary`2"/> if the key already exists.
		/// </summary>
		/// <returns>
		/// The new value for the key. This will be either be addValue (if the key was absent) or the result of updateValueFactory (if the key was present).
		/// </returns>
		/// <param name="key">The key to be added or whose value should be updated</param><param name="addValue">The value to be added for an absent key</param><param name="updateValueFactory">The function used to generate a new value for an existing key based on the key's existing value</param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is a null reference (Nothing in Visual Basic).-or-<paramref name="updateValueFactory"/> is a null reference (Nothing in Visual Basic).</exception><exception cref="T:System.OverflowException">The dictionary contains too many elements.</exception>
		public virtual IGameComponent AddOrUpdate(string key, IGameComponent addValue,
												  Func<string, IGameComponent, IGameComponent> updateValueFactory)
		{
			return _children.AddOrUpdate(key, addValue, updateValueFactory);
		}
Пример #48
0
        public void Dispose()
        {
            lock (this)
            {
                IGameComponent[] array = new IGameComponent[this.Components.Count];
                this.Components.CopyTo(array, 0);
                for (int i = 0; i < array.Length; i++)
                {
                    IDisposable disposable = array[i] as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                IDisposable disposable2 = this.graphicsDeviceManager as IDisposable;
                if (disposable2 != null)
                {
                    disposable2.Dispose();
                }
                this.UnhookDeviceEvents();

                if (this.Disposed != null)
                {
                    this.Disposed(this, EventArgs.Empty);
                }
            }
        }
Пример #49
0
 // All highscores stuff
 public static bool FilterHighscore(IGameComponent gc)
 {
     return gc is HighscoreComponent;
 }
Пример #50
0
 public GameComponentWrapper(IGameComponent component, Game game) :
     base(game)
 {
     Component = component;
 }
Пример #51
0
		/// <summary>
		/// Adds the specified key and value to the dictionary.
		/// </summary>
		/// <param name="key">The key of the element to add.</param><param name="value">The value of the element to add. The value can be null for reference types.</param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.</exception><exception cref="T:System.ArgumentException">An element with the same key already exists in the <see cref="T:System.Collections.Generic.Dictionary`2"/>.</exception>
		public virtual void Add(string key, IGameComponent value)
		{
			_children.Add(key, value);
		}
Пример #52
0
 public bool HasComponent(IGameComponent component)
 {
     return Components.Contains(component);
 }
 public GameComponentCollectionEventArgs(IGameComponent gameComponent)
 {
     GameComponent = gameComponent;
 }
Пример #54
0
        public void RemoveComponent(IGameComponent component)
        {
            var match = Components.FirstOrDefault(c => c == component);
            if (match == null)
                return;

            Components.Remove(match);
            match.Disable();
        }
Пример #55
0
        private Task PlayerDisconnecting(IGameComponent arg)
        {
            var player = (IPlayer)arg;
            player.Deleting -= this.PlayerDisconnecting;
            this.Disconnect((IPlayer)arg);

            if (player.CurrentRoom == null)
            {
                return Task.FromResult(0);
            }

            IEnumerable<IPlayer> remainingPlayersInRoom = player.CurrentRoom.Occupants
                .Where(character => character is IPlayer && character != player)
                .Cast<IPlayer>();
            foreach (IPlayer occupant in remainingPlayersInRoom)
            {
                this.playerConnections[occupant].SendMessage($"\r{player.Information.Name} left the realm.\r\n");
            }

            return Task.FromResult(0);
        }
Пример #56
0
 public void AddComponent(IGameComponent component)
 {
     Components.Add(component);
 }