private IReadOnlyCollection <ICommand> UpdateRules(GameTime gameTime) { var entities = _grid.GetEntities(); var expressions = _grid.GetExpressions(); var result = _parser.Process(expressions, entities); foreach (var command in result.Commands) { _doCommandsHandler.Apply(command, gameTime); } entities = _grid.GetEntities(); entities.ClearStatesAll(); result.Rules.ApplyAll(entities); List <ICommand> commands = new List <ICommand>(); var weakEntities = entities.Where(e => e.IsWeak); foreach (var weakEntity in weakEntities) { if (!_grid.HasEntities(weakEntity.Coordinates, e => e.IsKilling && e != weakEntity)) { continue; } var command = new ExitGameCommand(weakEntity); _doCommandsHandler.Apply(command, gameTime); commands.Add(command); _pipeline.Subscribe(new Sprite(weakEntity.Position, _resources.GetAnimationSmoke(0.04f), 99)); } return(result.Commands.Concat(commands).ToList()); }
// Use this for initialization void Start() { bgManager = GetComponent <BackgroundManager>(); egc = FindObjectOfType <ExitGameCommand>(); }
private void Apply(ExitGameCommand command, GameTime gameTime) { _grid.Enter(command.Entity, command.Coordinates); command.Entity.SetCoordinates(command.Coordinates, gameTime); _pipeline.Subscribe(command.Entity); }
private void Apply(ExitGameCommand command, GameTime gameTime) { _grid.Exit(command.Entity); command.Entity.ClearPosition(); _pipeline.Unsubscribe(command.Entity); }
// Update is called once per frame void Update() { foreach (var item in keyMap.OnReleasedKeyMap) { if (Input.GetKeyUp(item.Key)) { Debug.Log(string.Format("onReleasedKeyMap Key Released {0}", item.Value.ToString())); //Command command = null; } } foreach (var item in keyMap.OnKeyDownMap) { if (Input.GetKey(item.Key)) { Command command = null; switch (item.Value) { case "OnlyAim": command = new OnlyAimCommand(); break; } if (command != null) { if (command is ICommand) { Commands.Push((ICommand)command); } command.Execute(MoveCommandTarget); } } if (Input.GetKeyDown(item.Key)) { Command command = null; switch (item.Value) { case "Moving": command = new MovingCommand(); break; case "CastArcaneBolt": command = new ArcaneBoltCommand(); break; case "CastFireBolt": command = new FireBoltCommand(); break; case "CastIceBolt": command = new IceBoltCommand(); break; case "RestartGame": command = new RestartGameCommand(); break; case "ExitGame": command = new ExitGameCommand(); break; } if (command != null) { if (command is ICommand) { Commands.Push((ICommand)command); } command.Execute(MoveCommandTarget); } } } }
// Use this for initialization void Start() { bgManager = GetComponent<BackgroundManager>(); egc = FindObjectOfType<ExitGameCommand>(); }
/// <summary> /// Creates a command according to the user input /// </summary> /// <param name="command">Command to be created</param> /// <returns>The created command</returns> public ICommand GetCommand(string command) { if (!this.CommandsList.ContainsKey(command)) { ICommand commandExecutor = null; switch (command) { case "help": { commandExecutor = new CheatCommand(this.Data, this.Notifier, this.NumberGenerator); break; } case "start": { commandExecutor = new InitializeGameCommand(this.Data, this.Notifier, this.NumberGenerator); break; } case "commands": { commandExecutor = new DisplayCommandsListCommand(this.Notifier); break; } case "top": { commandExecutor = new DisplayScoreboardCommand(this.Scoreboard); break; } case "quit": { commandExecutor = new QuitGameCommand(this.Notifier); break; } case "exit": { commandExecutor = new ExitGameCommand(this.Notifier); break; } case "empty": { commandExecutor = new EmptyCommand(); break; } default: { commandExecutor = this.ProcessGuessAndReturnAppropriateCommand(command); break; } } this.CommandsList.Add(command, commandExecutor); return commandExecutor; } else { return this.CommandsList[command]; } }