/// <summary> /// Gets the next decision of the owner of this battle position /// Uses AI if an NPC, otherwise gets player input /// </summary> /// <returns>the next battle choice</returns> public void GetNextDecision() { battle.waitingForPlayerInput = false; BattleChoice nextChoice = null; if (trainer.GetType() == typeof(Trainer)) { //get random move from pokemon's movepool Random random = new Random(); while (nextChoice == null) { int num = random.Next(0, 3); if (pokemon.move[num] != null) { nextChoice = BattleChoice.UseMove(pokemon.move[num], GetRandomOpponentTarget()); } } choice = nextChoice; } else { lock (battle.lockObject) { battle.waitingForPlayerInput = true; battle.waitingIndex = index; //get player input Monitor.Wait(battle.lockObject); if (choice == null) { throw new Exception(); } } } }
public override void HandleInput(GamePadState gamePadState, KeyboardState keyState, MouseState mouseState) { BattleMenu.HandleInput(gamePadState, keyState, mouseState, this); //if the battle is waiting for player input if (state == State.Input) { //get input based on key presses lock (battle.lockObject) { if (Input.InputHandler.WasKeyPressed(keyState, Keys.D1, 10) && battle.Positions[battle.waitingIndex].pokemon.move[0] != null) { BattleChoice nextChoice = BattleChoice.UseMove(battle.Positions[battle.waitingIndex].pokemon.move[0], battle.Positions[1]); battle.Positions[battle.waitingIndex].choice = nextChoice; battle.waitingForPlayerInput = false; Monitor.Pulse(battle.lockObject); } else if (Input.InputHandler.WasKeyPressed(keyState, Keys.D2, 10) && battle.Positions[battle.waitingIndex].pokemon.move[1] != null) { BattleChoice nextChoice = BattleChoice.UseMove(battle.Positions[battle.waitingIndex].pokemon.move[1], battle.Positions[1]); battle.Positions[battle.waitingIndex].choice = nextChoice; battle.waitingForPlayerInput = false; Monitor.Pulse(battle.lockObject); } else if (Input.InputHandler.WasKeyPressed(keyState, Keys.D3, 10) && battle.Positions[battle.waitingIndex].pokemon.move[2] != null) { BattleChoice nextChoice = BattleChoice.UseMove(battle.Positions[battle.waitingIndex].pokemon.move[2], battle.Positions[1]); battle.Positions[battle.waitingIndex].choice = nextChoice; battle.waitingForPlayerInput = false; Monitor.Pulse(battle.lockObject); } else if (Input.InputHandler.WasKeyPressed(keyState, Keys.D4, 10)) { BattleChoice nextChoice = BattleChoice.RunFromBattle(); battle.Positions[battle.waitingIndex].choice = nextChoice; battle.waitingForPlayerInput = false; Monitor.Pulse(battle.lockObject); } } } }
public static void HandleInput(GamePadState gamePadState, KeyboardState keyState, MouseState mouseState) { if (battleScreen.state == State.Input) { if (!inMenu) //if selecting an option { //go in the menu if (Input.InputHandler.WasKeyPressed(keyState, Keys.Z, 10) || Input.InputHandler.WasKeyPressed(keyState, Keys.Down, 10)) { inMenu = true; } //go right if (Input.InputHandler.WasKeyPressed(keyState, Keys.Right, 10)) { optionChoice = (byte)(optionChoice < (byte)3 ? optionChoice + 1 : 0); } //go left if (Input.InputHandler.WasKeyPressed(keyState, Keys.Left, 10)) { optionChoice = (byte)(optionChoice > (byte)0 ? optionChoice - 1 : 3); } } else //else if currently in an option { //go out of the menu to select an option if (Input.InputHandler.WasKeyPressed(keyState, Keys.X, 10) || Input.InputHandler.WasKeyPressed(keyState, Keys.Up, 10)) { inMenu = false; } lock (battle.lockObject) { switch (optionChoice) { //FIGHT case 0: //use move if (Input.InputHandler.WasKeyPressed(keyState, Keys.Z, 10)) { if (pokemon.pokemon.move[fightChoice] != null) { battle.Positions[battle.waitingIndex].choice = BattleChoice.UseMove(battle.Positions[battle.waitingIndex].pokemon.move[fightChoice], battle.Positions[1]); battle.waitingForPlayerInput = false; Monitor.Pulse(battle.lockObject); } } //go right if (Input.InputHandler.WasKeyPressed(keyState, Keys.Right, 10)) { fightChoice = (byte)(fightChoice < (byte)3 ? fightChoice + 1 : 0); } //go left if (Input.InputHandler.WasKeyPressed(keyState, Keys.Left, 10)) { fightChoice = (byte)(fightChoice > (byte)0 ? fightChoice - 1 : 3); } break; //POKE case 1: //switch pokemon if (Input.InputHandler.WasKeyPressed(keyState, Keys.Z, 10)) { if (player.currentPokemon[pokeChoice] != null) { battle.Positions[0].SwitchPokemon(player.currentPokemon[pokeChoice]); battle.waitingForPlayerInput = false; Monitor.Pulse(battle.lockObject); } } //go right if (Input.InputHandler.WasKeyPressed(keyState, Keys.Right, 10)) { pokeChoice = (byte)(pokeChoice < (byte)5 ? pokeChoice + 1 : 0); } //go left if (Input.InputHandler.WasKeyPressed(keyState, Keys.Left, 10)) { pokeChoice = (byte)(pokeChoice > (byte)0 ? pokeChoice - 1 : 5); } break; //ITEM case 2: //use item if (Input.InputHandler.WasKeyPressed(keyState, Keys.Z, 10)) { if (player.inventory[itemChoice] != null) { battle.Positions[battle.waitingIndex].choice = BattleChoice.UseItem(Item.getItem(battle.Positions[battle.waitingIndex].trainer.inventory[itemChoice].itemID), battle.Positions[1]); battle.waitingForPlayerInput = false; Monitor.Pulse(battle.lockObject); } } //go right if (Input.InputHandler.WasKeyPressed(keyState, Keys.Right, 10)) { itemChoice = (itemChoice < itemOptions.Length - 1 ? itemChoice + 1 : 0); } //go left if (Input.InputHandler.WasKeyPressed(keyState, Keys.Left, 10)) { itemChoice = (itemChoice > 0 ? itemChoice - 1 : itemOptions.Length - 1); } break; //RUN case 3: //get the f**k out of there (or try to atleast) if (Input.InputHandler.WasKeyPressed(keyState, Keys.Z, 10)) { battle.Positions[battle.waitingIndex].choice = BattleChoice.RunFromBattle(); battle.waitingForPlayerInput = false; Monitor.Pulse(battle.lockObject); } break; } } } } }