예제 #1
0
 public Battle(ITrainer player, ITrainer enemyTrainer)
 {
     Player       = player;
     EnemyTrainer = enemyTrainer;
     BattleAux    = new BattleAux(player, enemyTrainer);
     InitializeCommandDictionary();
 }
예제 #2
0
        private bool PromptTrainerForPokemonMove()
        {
            bool keepBattleGoing = true;
            int  chosenMove      = BattleAux.KeepPlayerChoosingMove(LIMIT_OF_MOVES_PER_POKEMON);

            PokemonAttack(Player.GetCurrentPokemon(), EnemyTrainer.GetCurrentPokemon(), chosenMove);

            return(keepBattleGoing);
        }
예제 #3
0
        private bool PromptPlayerToChooseItem()
        {
            int chosenStackedItemsIndex = BattleAux.KeepPlayerChoosingItem(Player.Items.Count);
            int chosenPokemonIndex      = BattleAux.KeepPlayerChoosingPokemon();

            IPokemon chosenPokemon = Player.PokemonTeam[chosenPokemonIndex].Pokemon;
            IItem    chosenItem    = Player.Items.ElementAt(chosenStackedItemsIndex).Value.FirstOrDefault();

            return(CheckIfShouldKeepBattleGoingAfterItemSelection(chosenItem, chosenStackedItemsIndex, chosenPokemon));
        }
예제 #4
0
        private bool KeepBattleGoingWhileBothPlayersHavePokemonLeft()
        {
            bool playerWon = false, keepBattleGoing, isChangingToNextAvailablePokemon;

            while (Player.HasAvailablePokemon() && EnemyTrainer.HasAvailablePokemon())
            {
                keepBattleGoing = false;
                isChangingToNextAvailablePokemon = false;

                if (Player.GetCurrentPokemon().HasFainted() && EnemyTrainer.HasAvailablePokemon())
                {
                    PromptPlayerToSelectPokemonAfterOwnPokemonFainted();
                    PlayerAction.PlayerSendsPokemon(Player.GetCurrentPokemon());
                    isChangingToNextAvailablePokemon = true;
                }
                else
                {
                    ConsoleBattleInfoPokemon.ShowBothPokemonStats(Player.GetCurrentPokemon(), EnemyTrainer.GetCurrentPokemon());
                    keepBattleGoing = PlayerMove();
                }

                if (keepBattleGoing && !isChangingToNextAvailablePokemon)
                {
                    if (EnemyTrainer.GetCurrentPokemon().HasFainted() && Player.HasAvailablePokemon())
                    {
                        if (BattleAux.CannotSendNextAvailablePokemon(isEnemyTrainer: true))
                        {
                            break;
                        }
                        else
                        {
                            PromptPlayerToSelectPokemonAfterEnemyPokemonFainted();
                            BattleAux.ShowTrainerSentPokemonMessage(isEnemyTrainer: true);
                            PlayerAction.PlayerSendsPokemon(Player.GetCurrentPokemon());
                        }
                    }
                    else
                    {
                        EnemyMove();
                    }
                }
            }

            if (Player.HasAvailablePokemon())
            {
                playerWon = true;
            }

            return(playerWon);
        }
예제 #5
0
        private void PromptPlayerToSelectPokemonAfterEnemyPokemonFainted()
        {
            int chosenPokemonIndex = 0;

            if (Player.PokemonTeam.Where(w => !w.Pokemon.HasFainted()).Count() > 1)
            {
                ConsoleUtils.ShowMessageAndWaitTwoSeconds($"{EnemyTrainer.GetType().Name} is about to send out {EnemyTrainer.GetCurrentPokemon().GetType().Name}");
                ConsoleUtils.ShowMessageBetweenEmptyLines("Which pokemon will you choose?");
                chosenPokemonIndex = BattleAux.KeepPlayerChoosingPokemon();
                SwitchCurrentPokemon(chosenPokemonIndex, isChangingAfterOwnPokemonFainted: true);
            }
            else
            {
                chosenPokemonIndex = Player.PokemonTeam.IndexOf(Player.PokemonTeam.Where(w => !w.Fainted).FirstOrDefault());
                SwitchCurrentPokemon(chosenPokemonIndex, isChangingAfterOwnPokemonFainted: true);
            }
        }
예제 #6
0
        private bool PromptPlayerToSelectPokemon()
        {
            var keepBattleGoingAfterPokemonSelection = false;

            if (Player.PokemonTeam.Where(pkmn => !pkmn.Fainted).Count() == 1)
            {
                ConsoleBattleInfoTrainer.ShowPlayerThereAreNoPokemonLeftToSwitch();
                return(keepBattleGoingAfterPokemonSelection);
            }

            int chosenPokemonIndex = BattleAux.KeepPlayerChoosingPokemon();

            SwitchCurrentPokemon(chosenPokemonIndex);
            keepBattleGoingAfterPokemonSelection = true;

            return(keepBattleGoingAfterPokemonSelection);
        }
예제 #7
0
        private static void ProcessAttack(IPokemon attackingPokemon, IPokemon targetPokemon, IMove move)
        {
            TypeEffect moveEffectOnPokemon = TypeComparer.GetMoveEffectivenessBasedOnPokemonType(move.Type, targetPokemon.Types.FirstOrDefault());

            int calculatedDamage = TypeDamageCalculator.CalculateDamage(attackingPokemon, targetPokemon, move, moveEffectOnPokemon);

            attackingPokemon.UseMove(move);

            if (move.StatusMoves != null)
            {
                BattleAux.ProcessStatusAttack(attackingPokemon, targetPokemon, move);
            }
            else
            {
                targetPokemon.ReceiveDamage(calculatedDamage);
                ConsoleBattleInfoPokemon.ShowPokemonReceivedDamage(targetPokemon, calculatedDamage);
                ConsoleBattleInfoTypes.ShowHowEffectiveTheMoveWas(moveEffectOnPokemon);
            }
        }
예제 #8
0
        private void SwitchCurrentPokemon(int chosenPokemon, bool isChangingAfterOwnPokemonFainted = false)
        {
            TrainerPokemon pokemon = Player.PokemonTeam[chosenPokemon];

            if (pokemon is null || (pokemon.Current && isChangingAfterOwnPokemonFainted))
            {
                return;
            }

            if (pokemon.Fainted)
            {
                ConsoleBattleInfoPokemon.ShowChosenPokemonIsNotAvailable();
                PlayerMove();
                return;
            }
            else if (pokemon.Current)
            {
                ConsoleBattleInfoPokemon.ShowChosenPokemonIsAlreadyInBattle();
                PlayerMove();
                return;
            }

            BattleAux.ShowDrawbackMessageAndSetChosenPokemonIndexAsCurrent(chosenPokemon);
        }