public static void Register(Assembly assembly, ICommandManager cmdManager) { var factoryTypeBase = typeof(RequestEntityFactory <>); IEnumerable <Type> ts = assembly.GetTypes();//assembly.GetExportedTypes(); foreach (var t in ts) { if (t.GetInterface(typeof(ICommand).Name) == null) { continue; } var cmdType = t.BaseType; while (cmdType != null) { if (!cmdType.FullName.StartsWith("LeonardoScriptCore.Serial.CommandBase")) { cmdType = cmdType.BaseType; continue; } var cmdInst = Activator.CreateInstance(t) as ICommand; var entityType = cmdType.GetGenericArguments().Last(); cmdManager.AddCommand(cmdInst); m_Factories[cmdInst.ID] = (IRequestEntityFactory)Activator.CreateInstance(factoryTypeBase.MakeGenericType(entityType)); break; } } }
public override void Update() { if (Keyboard.GetState().IsKeyDown(Keys.Up)) { _moveCommand.Direction = new Vector2(0, -1); _moveCommand.Speed = 3; _commandManager.AddCommand(_moveCommand); } else if (Keyboard.GetState().IsKeyDown(Keys.Down)) { _moveCommand.Direction = new Vector2(0, 1f); _moveCommand.Speed = 3; _commandManager.AddCommand(_moveCommand); } }
public override void OnCollision(IEntity entity) { if (!(entity is Ball)) { return; } if (entity.Position.X + entity.Width >= Width) { _updateScoreCommand.IncrementPlayerScore = false; _commandManager.AddCommand(_updateScoreCommand); } else if (entity.Position.Y <= 0) { _updateScoreCommand.IncrementPlayerScore = true; _commandManager.AddCommand(_updateScoreCommand); } }
public void Handle(Trigger trigger, IEntity entity) { if ((entity is Ball) == false) { return; } if (_updateScoreCommand == null) { var score = (ScoreTextBox)_entityManager.GetEntity(Constants.EntityIds.ScoreId); _updateScoreCommand = new UpdateScoreCommand(score) { IncrementPlayerScore = false }; } _commandManager.ClearQueue(); _commandManager.AddCommand(_updateScoreCommand); _commandManager.AddCommand(_newRoundCommand); //_commandManager.AddCommand(new FreezeCommand(1)); }
public void Execute() { if (_freezeTime == default) { _freezeTime = DateTime.Now.AddSeconds(_seconds); } if (DateTime.Now < _freezeTime) { _commandManager.ClearQueue(); _commandManager.AddCommand(this); } }
public static void Register(IEnumerable <ICommand> commands, ICommandManager cmdManager) { var factoryTypeBase = typeof(RequestEntityFactory <>); foreach (var c in commands) { var cmdType = c.GetType().BaseType; while (cmdType != null) { if (!cmdType.FullName.StartsWith("LeonardoScriptCore.Serial.CommandBase")) { cmdType = cmdType.BaseType; continue; } var entityType = cmdType.GetGenericArguments().Last(); cmdManager.AddCommand(c); m_Factories[c.ID] = (IRequestEntityFactory)Activator.CreateInstance(factoryTypeBase.MakeGenericType(entityType)); break; } } }
public override void Update() { _commandManager.AddCommand(_moveCommand); }