/// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } #region Directions if (Keyboard.GetState().IsKeyDown(Keys.Right) && LastKey.IsKeyUp(Keys.Right) && ((int)Chosen.X) < TmxMap.Width - 1) { Chosen = Grid[((int)Chosen.X) + 1, ((int)Chosen.Y)]; } if (Keyboard.GetState().IsKeyDown(Keys.Left) && LastKey.IsKeyUp(Keys.Left) && ((int)Chosen.X) > 0) { Chosen = Grid[((int)Chosen.X) - 1, ((int)Chosen.Y)]; } if (Keyboard.GetState().IsKeyDown(Keys.Up) && LastKey.IsKeyUp(Keys.Up) && ((int)Chosen.Y) > 0) { Chosen = Grid[((int)Chosen.X), ((int)Chosen.Y) - 1]; } if (Keyboard.GetState().IsKeyDown(Keys.Down) && LastKey.IsKeyUp(Keys.Down) && ((int)Chosen.Y) < TmxMap.Height - 1) { Chosen = Grid[((int)Chosen.X), ((int)Chosen.Y) + 1]; } #endregion if (Keyboard.GetState().IsKeyDown(Keys.X) && LastKey.IsKeyUp(Keys.X)) { if (StateGame == GameStates.MODE) { Pvp = false; StateGame = GameStates.SELECT; } if (StateGame == GameStates.MOVE) { ActiveUnit.Manager.PauseOrPlay(); ActiveUnit = null; StateGame = GameStates.SELECT; } } if (Keyboard.GetState().IsKeyDown(Keys.Z) && LastKey.IsKeyUp(Keys.Z)) { switch (StateGame) { case GameStates.MODE: Pvp = true; StateGame = GameStates.SELECT; break; case GameStates.SELECT: if (Chosen.Unit != null && Chosen.Unit.Player == Turn) { WalkOrAttack = true; StateGame = GameStates.MOVE; ActiveUnit = Chosen.Unit; ActiveUnit.Manager.PauseOrPlay(); } break; case GameStates.MOVE: if (Chosen.Unit == null && ActiveUnit.ReachableTiles(Grid, true) .Contains(Chosen)) { StateGame = GameStates.ACTION; Move = new Move(ActiveUnit, Chosen, false); Move.Execute(); WalkOrAttack = false; } break; case GameStates.ACTION: if (Chosen.Unit != null && ActiveUnit.ReachableTiles(Grid, false) .Contains(Chosen)) { Heal = new Heal(ActiveUnit, Chosen.Unit, false); if (ActiveUnit.GetActions(Grid).Any( action => action.Heal != null && action.Heal.Target.Player && action.Heal.GetType() == Heal.GetType() && action.Heal.Equals(Heal))) { Heal.Execute(); } Attack = new Attack(ActiveUnit, Chosen.Unit, false); if (ActiveUnit.GetActions(Grid).Any( action => action.Attack != null && action.Attack.GetType() == Attack.GetType() && action.Attack.Equals(Attack))) { Attack.Execute(); } ActiveUnit.Manager.PauseOrPlay(); } else { ActiveUnit.Manager.PauseOrPlay(); ActiveUnit = null; } StateGame = CheckAndDrawWinner(); if (StateGame == GameStates.SELECT) { if (Pvp) { Turn = !Turn; } else { this.Window.Title = "Computing..."; ComputerPlayer.MakeTurn(Map, 1); StateGame = CheckAndDrawWinner(); if (StateGame == GameStates.VICTORY) { break; } } Chosen = TileNextTurn(Turn); } break; default: break; } } this.Window.Title = $"Water Emblem Player {(Turn?1:2)}'s Turn"; LastKey = Keyboard.GetState(); base.Update(gameTime); }