public void TransitionToState([NotNull] IControllerState targetState) { if (targetState == null) { throw new ArgumentNullException(nameof(targetState)); } try { CurrentState.OnExit(); } catch (Exception ex) { Log.Error() .Exception(ex) .Message($"Unexpected exception leaving state {CurrentState.Name}") .Write(); } CurrentState = new StateLoggingDecorator(targetState); try { CurrentState.OnEnter(); } catch (Exception ex) { Log.Error() .Exception(ex) .Message($"Unexpected exception entering state {targetState.Name}") .Write(); } }
/// <summary> /// Run game logic here such as updating the world, /// checking for collisions, handling input and drawing the game. /// This method will be called as frequently as possible, /// when the Windows message queue is empty. /// Check GameTime to get the elapsed time since the last update. /// </summary> /// <param name="gameTime">Game time</param> /// <param name="renderer">A Renderer</param> /// <param name="keyboardState">A keyboard state</param> public void Run(GameTime gameTime, IGraphics renderer, IControllerState keyboardState) { if (this.levelStat == LevelChangeStatus.NoChange) { if (Collisions.GetPlayerTile(this.level.Player) == TileType.Next) { this.level.LevelIndex++; this.levelStat = LevelChangeStatus.Change; } else if (Collisions.GetPlayerTile(this.level.Player) == TileType.Back) { this.level.LevelIndex--; this.levelStat = LevelChangeStatus.Change; } else { this.level.Update(gameTime, keyboardState); this.level.Draw(gameTime, renderer); } } else { this.level.UpdateLevel(); this.levelStat = LevelChangeStatus.NoChange; } }
public StateAssigner(IPureDataFacade pureDataFacade, IControllerStateFactory controllerStateFactory = null) { var stateFactory = controllerStateFactory ?? new ControllerStateFactory(); idleState_ = stateFactory.CreateIdleState(); carrierState_ = stateFactory.CreateCarrierState(pureDataFacade); modulatorState_ = stateFactory.CreateModulatorState(pureDataFacade); }
public EditController(IControllerState state = null) { this.state = state ?? new ControllerState(); commands = new Dictionary <string, Func <IControllerState, string[], CommandResult> > { { "insert", InsertCommand } }; }
public void InsertControllerState(Controller controller, IControllerState controllerState) { using (var ctx = _repositoryService.GetContext()) { InsertControllerState(ctx, controller, controllerState); ctx.SaveChanges(); } }
public void SetUp() { carrierControllerStateMock_ = Substitute.For <IControllerState>(); modulatorControllerStateMock_ = Substitute.For <IControllerState>(); idleControllerStateMock_ = Substitute.For <IControllerState>(); stateAssignerMock_ = Substitute.For <IStateAssigner>(); controllerBehaviourMock_ = Substitute.For <IControllerBehaviour>(); }
void InsertControllerState(ISqLiteContext ctx, Controller controller, IControllerState controllerState) { var stateModel = new ControllerStateInformation(); stateModel.State = controllerState.State; stateModel.PowerConsumption = controllerState.PowerConsumption; stateModel.Controller = controller; ctx.Add(stateModel); }
//////////////// /// Commands /// //////////////// private static CommandResult InsertCommand(IControllerState state, string[] args) { if (args.Length < 1) { return(new CommandResult(false, "Pass argument for insert")); } state.Text.Insert(state.CurrentPosition, args[0]); state.CurrentPosition += args[0].Length; return(new CommandResult(true, null)); }
public bool Apply(IControllerState state) { if (state.Text.Length <= state.CurrentPosition) { return(false); } deletedChar = state.Text[state.CurrentPosition]; state.Text.Remove(state.CurrentPosition, 1); return(true); }
public static CommandResult Backspace(IControllerState state, string[] args) { if (state.CurrentPosition <= 0) { return(new CommandResult(false, "No symbols on left side")); } state.CurrentPosition--; state.Text.Remove(state.CurrentPosition, 1); return(new CommandResult(true, null)); }
private void Start() { _animation = GetComponent <Animation>(); if (!_animation) { Debug.Log( "The character you would like to control doesn't have animations. Moving her might look weird."); } else { _animation[Animations.Run.name].speed = ControllerParams.RunAnimationSpeed; _animation[Animations.TurnToRight.name].speed = ControllerParams.TurningAnimationSpeed; _animation[Animations.TurnToLeft.name].speed = ControllerParams.TurningAnimationSpeed; for (int i = 0; i < Animations.JumpDown.Length; i++) { _animation[Animations.JumpDown[i].name].speed = ControllerParams.JumpDownAnimationSpeed; } for (int i = 0; i < Animations.JumpDown.Length; i++) { _animation[Animations.JumpUp[i].name].speed = ControllerParams.JumpUpAnimationSpeed; } } track = TrackAbstract.GetInstance(); if (!track) { track = null; Debug.Log("No Track found. Character can`t move without Track"); } _transform = transform; characterController = GetComponent <CharacterController>(); instance = this; ControllerParams.JumpVerticalSpeed = Mathf.Sqrt(2 * ControllerParams.JumpHeight * ControllerParams.Gravity); ControllerColliderDeadHeight = characterController.center.y + characterController.height * 0.5f; runingState = new RuningState(this); turningState = new TurningState(this); jumpingState = new JumpingState(this); disallowedTurnState = new DisallowedTurningState(this); stramedState = new StameredState(this); deadState = new DeadState(this); shieldAttackState = new ShieldAttackState(this, ControllerParams.ShieldAttackTime); swordAttackState = new SwordAttackState(this, ControllerParams.SwordAttackTime); ropeRollingState = new RopeRollingState(this); colliderRelSaved = characterController.center; PrepareToReplay(); if (footFlares) { footFlares.maxBrightness = MaxFlireBrightness; footFlares.TurnOff(); } life = new Life(); }
public void Setup() { this.settings = new GlobalEditorSettings { ThrowExceptionIfCommandNotFound = false }; this.state = new ControllerState(); this.state.Text.Append("abcdefg"); this.state.CurrentPosition = 3; // TODO: заменить на реализацию "горячих" настроек this.controller = new EditController(this.state, this.settings.ThrowExceptionIfCommandNotFound); this.SetupActions(); }
public Controller(IStateAssigner stateAssigner, IControllerBehaviour controllerBehaviour) { stateAssigner_ = stateAssigner; controllerBehaviour_ = controllerBehaviour; controllerBehaviour_.TransformChanged += OnTransformChanged; controllerBehaviour_.TriggerPressed += OnTriggerPressed; controllerBehaviour_.TriggerReleased += OnTriggerReleased; controllerBehaviour_.ThumbstickPositionChanged += OnThumbStickPositionChanged; controllerBehaviour_.Updated += OnUpdated; currentState_ = stateAssigner_.Unassign(this); currentState_.OnStateSelected(); }
private void ChangeStateTo(IControllerState nextState) { currentState_.OnStateDeselected(); currentState_.FreqChanged -= OnFreqChanged; currentState_.AmpChanged -= OnAmpChanged; currentState_.WaveformUpdated -= OnWaveformUpdated; currentState_.ResonanceChanged -= OnResonanceChanged; currentState_ = nextState; controllerBehaviour_.IndicatorBehaviour.FuncText = currentState_.Identifier; controllerBehaviour_.WaveVisibility = currentState_.Identifier != "idle"; currentState_.OnStateSelected(); currentState_.OnDistanceChanged(distance_); currentState_.FreqChanged += OnFreqChanged; currentState_.AmpChanged += OnAmpChanged; currentState_.WaveformUpdated += OnWaveformUpdated; currentState_.ResonanceChanged += OnResonanceChanged; }
public void SetUp() { state = new ControllerState(); state.Text.Append("abcdefg"); state.CurrentPosition = 3; }
public abstract void Update(GameTime gameTime, IGraphics renderer, IControllerState keyboardState);
/// <summary> /// Method to update the character /// </summary> /// <param name="gameTime">A game time</param> /// <param name="keyboardState">A keyboard state</param> public abstract void Update(GameTime gameTime, IControllerState keyboardState);
/// <summary> /// Move the Player /// </summary> /// <param name="gameTime">Game time</param> /// <param name="keyboardState">Keyboard state</param> private void Move(GameTime gameTime, IControllerState keyboardState) { PointF existingPosition = this.Position; Point existingMapPosition = this.MapPosition; var move = (float)(PlayerSpeed * gameTime.ElapsedTime.TotalSeconds); if (keyboardState.IsKeyDown(Keys.Left)) { this.Position = new PointF(this.Position.X - move, this.Position.Y); this.WalkDirection = Direction.Left; } else if (keyboardState.IsKeyDown(Keys.Right)) { this.Position = new PointF(this.Position.X + move, this.Position.Y); this.WalkDirection = Direction.Right; } else if (keyboardState.IsKeyDown(Keys.Up)) { this.Position = new PointF(this.Position.X, this.Position.Y - move); this.WalkDirection = Direction.Up; } else if (keyboardState.IsKeyDown(Keys.Down)) { this.Position = new PointF(this.Position.X, this.Position.Y + move); this.WalkDirection = Direction.Down; } else { this.WalkDirection = Direction.Still; return; } // The position on the map is represented by two integers (pixel accuracy) this.MapPosition = new Point((int)Math.Round(this.Position.X), (int)Math.Round(this.Position.Y)); // Check if we can move on the next position // (not leaving the map and not colliding with walls or other objects) if (Collisions.IsNotCollding(this)) { // Player was moved return; } // Player cannot go here, return the old coords this.Position = existingPosition; this.MapPosition = existingMapPosition; }
/// <summary> /// Updates the enemy /// </summary> /// <param name="gameTime">Gametime</param> /// <param name="keyboardState">Keyboard state</param> public override void Update(GameTime gameTime, IControllerState keyboardState) { this.HolsterWeapon(gameTime); if (this.IsAlive) { if (Collisions.PlayerIsVisible(this, this.WalkDirection)) { double angleInDegrees = Collisions.GetBearing(this, Collisions.GetPlayer()); int tileRange = Collisions.GetTileRange(this, Collisions.GetPlayer()); Console.WriteLine("Player spotted: {0:F1}", angleInDegrees); this.Chase(gameTime, angleInDegrees, tileRange); } else { this.HolsterWeapon(gameTime); this.isHunting = false; this.MoveRandom(gameTime); } } else { this.WalkDirection = Direction.Still; } }
public bool Apply(IControllerState state) { state.Text.Insert(state.CurrentPosition, additionChar); state.CurrentPosition++; return(true); }
public bool Apply(IControllerState state) { // здесь умышленно нет проверки на допустимость позиции. пусть контроллер сам научится защащаться от команд, ломающих состояние state.CurrentPosition += moveValue; return(true); }
/// <summary> /// Updates the hero state /// </summary> /// <param name="gameTime">Game time</param> /// <param name="keyboardState">Keyboard state</param> public override void Update(GameTime gameTime, IControllerState keyboardState) { this.Move(gameTime, keyboardState); this.OnSpacebar(keyboardState, gameTime); this.OnDigitOne(keyboardState, gameTime); this.RankUp(); this.CheckTrigger(gameTime, keyboardState); this.SetInitialStatus(gameTime); }
internal void SetState(IControllerState state) { currentState = state; }
/// <summary> /// Inspects objects when space is pressed /// </summary> /// <param name="keyboardState">key board state</param> /// <param name="gameTime">game time</param> private void OnSpacebar(IControllerState keyboardState, GameTime gameTime) { if (keyboardState.IsKeyDown(Keys.Space)) { this.InspectNearbyObjects(gameTime); } }
/// <summary> /// heals the hero when "1" is pressed /// </summary> /// <param name="keyboardState">keyboard state</param> /// <param name="gameTime">game time</param> private void OnDigitOne(IControllerState keyboardState, GameTime gameTime) { if (keyboardState.IsKeyDown(Keys.D1)) { if (this.MedKits > 0 && !this.isMedKitUsed) { this.Heal(gameTime); } } else { this.PrepareMedKit(gameTime); } }
public ControllerState(IControllerState source) { this.Text = new StringBuilder(source.Text.ToString()); this.CurrentPosition = source.CurrentPosition; }
public bool Revert(IControllerState state) { throw new NotImplementedException("Реализуй самостоятельно"); }
/// <summary> /// Updates all characters in the game /// </summary> /// <param name="gameTime">Game time</param> /// <param name="keyboardState">Keyboard state</param> public void Update(GameTime gameTime, IControllerState keyboardState) { if (this.Player.IsAlive) { Door doorToRemove = null; foreach (Sprite sprite in this.allObjects) { if (sprite is ILiving) { (sprite as ILiving).Update(gameTime, keyboardState); } else if (sprite is Door) { var door = sprite as Door; if (!door.IsLocked) { doorToRemove = door; } } } if (doorToRemove != null) { this.allObjects.Remove(doorToRemove); } } else { GameIsRunning = false; } }
/// <summary> /// Checks if the key for shooting is pressed /// </summary> /// <param name="keyboardState">Keyboard state</param> /// <returns></returns> private bool ShootKeyPressed(IControllerState keyboardState) { if (keyboardState.IsKeyDown(Keys.A)) { this.ShootDirection = SearchPattern.Left; } else if (keyboardState.IsKeyDown(Keys.D)) { this.ShootDirection = SearchPattern.Right; } else if (keyboardState.IsKeyDown(Keys.W)) { this.ShootDirection = SearchPattern.Up; } else if (keyboardState.IsKeyDown(Keys.S)) { this.ShootDirection = SearchPattern.Down; } else { return false; } return true; }
/// <summary> /// Checks the trigger /// </summary> /// <param name="gameTime">Game time</param> /// <param name="keyboardState">Keyboard state</param> private void CheckTrigger(GameTime gameTime, IControllerState keyboardState) { if (this.Bullets > 0 && !this.GunOut) { if (this.ShootKeyPressed(keyboardState)) { this.Shoot(gameTime); } } else { this.HolsterWeapon(gameTime); } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, handling input and drawing the game. /// </summary> public override void Update(GameTime gameTime, IGraphics renderer, IControllerState keyboardState) { this.game.Run(gameTime, renderer, keyboardState); }
/// <summary> /// Initializes the state machine and optionally sets the starting state. /// </summary> /// <param name="startState"></param> public void Initialize(IControllerState startState) { TransitionToState(startState); }
public StateLoggingDecorator(IControllerState targetState) { decoratedState = targetState; }
public EditController(IControllerState state, bool throwExceptionIfCommandNotFound = false) { this.state = state; this.throwExceptionIfCommandNotFound = throwExceptionIfCommandNotFound; }