Пример #1
0
        public static void ChallengeRival(PokemonTrainer userTrainer)
        {
            List <string> userChoices = new List <string>();

            for (int i = 1; i < 11; i++)
            {
                double timePassed      = .25 * Math.Pow(i, 1.9);
                int    yearsPassed     = (int)timePassed;
                int    remainingMonths = (int)((timePassed - yearsPassed) * 12);
                string monthName       = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(remainingMonths + 1);

                userChoices.Add($"Bary Yoke in {monthName}, {2000 + yearsPassed}");
            }

            int userInputIndex = Menu.GetUserInputIndex(userChoices, true);

            if (userInputIndex == -1)
            {
                return;
            }

            RivalTrainer rival = new RivalTrainer("Bary Yoke", userInputIndex + 1);

            rival.SetPokemons(userTrainer.StarterPokemon);
            rival.Introduction(userTrainer);
            Battle.FightTrainer(userTrainer, rival);
        }
Пример #2
0
 public void Introduction(PokemonTrainer userTrainer)
 {
     Console.WriteLine($"{this.Name}: I've been waiting to battle you ever since you took my Popokénom, {userTrainer.Name}.");
     Console.WriteLine($"{this.Name}: I was supposed to get {userTrainer.StarterPokemon}, but Grandpa gave the last one to some stranger.");
     Console.WriteLine($"{this.Name}: That's okay because {this.StarterPokemon} and I have been getting along.");
     Console.WriteLine($"{this.Name}: Prepare for battle!");
 }
Пример #3
0
        public static void InteractWithItems(Pokemon userPokemon, PokemonTrainer userTrainer, Pokemon opponent)
        {
            List <string> userItems = new List <string>();

            foreach (IItem item in userTrainer.Items)
            {
                string itemName = item.Name;
                userItems.Add(itemName);
            }
            int userInputIndex = Menu.GetUserInputIndex(userItems, true);

            if (userInputIndex == -1)
            {
                return;
            }
            IItem itemChosen = userTrainer.Items[userInputIndex];

            if (itemChosen.PokemonAffected == "user")
            {
                userTrainer.Items[userInputIndex].Use(userPokemon, userTrainer);
            }
            else
            {
                userTrainer.Items[userInputIndex].Use(opponent, userTrainer);
            }

            OpponentMightAttack(userPokemon, opponent);
        }
Пример #4
0
        public static void Save(PokemonTrainer userTrainer)
        {
            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream(System.AppDomain.CurrentDomain.BaseDirectory + @"\saves.bin", FileMode.Create, FileAccess.Write, FileShare.None);

            formatter.Serialize(stream, userTrainer);
            stream.Close();
        }
Пример #5
0
        public static void FightPokemon(PokemonTrainer userTrainer, Pokemon opponent)
        {
            List <string> menuChoices = new List <string> {
                "Attack", "Change Popokenom", "Item", "Run"
            };

            while (opponent.Hp > 0 && !userTrainer.AllPokemonsFainted())
            {
                if (userTrainer.PokemonOut.Hp == 0)
                {
                    ChangePokemon(userTrainer, false);
                }

                int userInputIndex = Menu.GetUserInputIndex(menuChoices, false);
                switch (userInputIndex)
                {
                case 0:
                    Attack(userTrainer.PokemonOut, opponent);
                    break;

                case 1:
                    Pokemon initialPokemon = userTrainer.PokemonOut;
                    ChangePokemon(userTrainer, true);
                    if (initialPokemon == userTrainer.PokemonOut)
                    {
                        break;
                    }
                    OpponentMightAttack(userTrainer.PokemonOut, opponent);
                    break;

                case 2:
                    InteractWithItems(userTrainer.PokemonOut, userTrainer, opponent);
                    // Opponent faints when it fails to break out of Pokeball.
                    if (opponent.Hp == 0)
                    {
                        return;
                    }
                    break;

                case 3:
                    if (Run(userTrainer.PokemonOut, opponent))
                    {
                        return;
                    }
                    ;
                    break;
                }
            }
            if (opponent.Hp == 0)
            {
                Console.WriteLine($"{opponent.Name} fainted.");
                userTrainer.PokemonOut.GainExp(opponent.ExpReleased);
            }
            else
            {
                Console.WriteLine($"{userTrainer.PokemonOut.Name} fainted.");
            }
        }
Пример #6
0
        public static PokemonTrainer Load()
        {
            IFormatter     formatter   = new BinaryFormatter();
            Stream         stream      = new FileStream(System.AppDomain.CurrentDomain.BaseDirectory + @"\saves.bin", FileMode.Open, FileAccess.Read);
            PokemonTrainer userTrainer = (PokemonTrainer)formatter.Deserialize(stream);

            stream.Close();
            return(userTrainer);
        }
Пример #7
0
        public static void FightTrainer(PokemonTrainer userTrainer, RivalTrainer opponentTrainer)
        {
            int nextPokemonIndex = 1;

            List <string> menuChoices = new List <string> {
                "Attack", "Change Popokenom", "Item", "Run"
            };

            Console.WriteLine($"{opponentTrainer.Name}: My {opponentTrainer.StarterPokemon} will beat your {userTrainer.StarterPokemon} for sure.");
            while (!opponentTrainer.AllPokemonsFainted() && !userTrainer.AllPokemonsFainted())
            {
                if (userTrainer.PokemonOut.Hp == 0)
                {
                    ChangePokemon(userTrainer, false);
                }
                if (opponentTrainer.PokemonOut.Hp == 0)
                {
                    Console.WriteLine($"{opponentTrainer.PokemonOut.Name} fainted.");
                    userTrainer.PokemonOut.GainExp(opponentTrainer.PokemonOut.ExpReleased);
                    Console.WriteLine($"{opponentTrainer.Name}: You did well, {opponentTrainer.PokemonOut.Name}.");
                    opponentTrainer.SwapPokemons(0, nextPokemonIndex++);
                    Console.WriteLine($"{opponentTrainer.Name}: {opponentTrainer.PokemonOut.Name}, let's catch up the slack!");
                }

                int userInputIndex = Menu.GetUserInputIndex(menuChoices, false);
                switch (userInputIndex)
                {
                case 0:
                    Attack(userTrainer.PokemonOut, opponentTrainer.PokemonOut);
                    break;

                case 1:
                    Pokemon initialPokemon = userTrainer.PokemonOut;
                    ChangePokemon(userTrainer, true);
                    if (initialPokemon == userTrainer.PokemonOut)
                    {
                        break;
                    }
                    OpponentMightAttack(userTrainer.PokemonOut, opponentTrainer.PokemonOut);
                    break;

                case 2:
                    InteractWithItems(userTrainer.PokemonOut, userTrainer, opponentTrainer.PokemonOut);
                    break;

                case 3:
                    Console.WriteLine($"{opponentTrainer.Name}: You can't run away from me, {userTrainer.Name}.");
                    break;
                }
            }
            if (opponentTrainer.AllPokemonsFainted())
            {
                Console.WriteLine($"{opponentTrainer.Name}: I'll have you next time.");
                userTrainer.Money += opponentTrainer.MoneyRewarded;
                Console.WriteLine($"{userTrainer.Name} earned ${opponentTrainer.MoneyRewarded}.");
            }
        }
Пример #8
0
 private static void IntroduceGame(PokemonTrainer userTrainer)
 {
     Console.WriteLine($"Hello there, {userTrainer.Name}! My name is not Nashkenazy, and this game might be called Popokénom.");
     Console.WriteLine("You'll notice that I put very little effort in making this game good.");
     Console.WriteLine("A Magikarp can be much stronger than Mew.");
     Console.WriteLine("In fact, it is the strongest Popokénom in this game.");
     Console.WriteLine("With that said, have fun!");
     Console.WriteLine();
 }
Пример #9
0
        public void Use(Pokemon userPokemon, PokemonTrainer userTrainer)
        {
            userTrainer.Items.Remove(this);
            int HpIncreased = (int)Math.Round((userPokemon.MaxHp * this.HpIncrease));

            if (userPokemon.Hp + HpIncreased > userPokemon.MaxHp)
            {
                HpIncreased = userPokemon.MaxHp - userPokemon.Hp;
            }
            userPokemon.Hp += HpIncreased;
            Console.WriteLine($"{userPokemon} recovered {HpIncreased} Hp to {userPokemon.Hp}");
        }
Пример #10
0
        private static void GetStarterPokemon(PokemonTrainer userTrainer)
        {
            Console.WriteLine("Choose your starter popokénom!");
            Console.WriteLine();

            int    userInputIndex = Menu.GetUserInputIndex(Pokemons.StarterPokemons, false);
            string pokemonChosen  = Pokemons.StarterPokemons[userInputIndex];

            userTrainer.StarterPokemon = pokemonChosen;
            userTrainer.CaptivePokemons.Add(new Pokemon(pokemonChosen, 1));
            Console.WriteLine($"Congratulations! {pokemonChosen} joined your party.");
        }
Пример #11
0
        static void Main(string[] args)
        {
            PokemonTrainer userTrainer    = new PokemonTrainer(null);
            int            titleMenuInput = Menu.GetUserInputIndex(new List <string> {
                "New Game", "Load"
            }, false);

            switch (titleMenuInput)
            {
            case 0:
                userTrainer = new PokemonTrainer(GetUserName());
                IntroduceGame(userTrainer);
                GetStarterPokemon(userTrainer);
                break;

            case 1:
                userTrainer = Menu.Load();
                break;
            }

            List <string> menuChoices = new List <string> {
                "Fight wild a Popokénom", "Challenge Rival", "Shop", "Save", "Quit"
            };

            while (true)
            {
                int userInput = Menu.GetUserInputIndex(menuChoices, false);
                switch (userInput)
                {
                case 0:
                    Menu.FightWildPokemon(userTrainer);
                    userTrainer.HeallAllPokemons();
                    break;

                case 1:
                    Menu.ChallengeRival(userTrainer);
                    userTrainer.HeallAllPokemons();
                    break;

                case 2:
                    Menu.PurchaseItem(userTrainer);
                    break;

                case 3:
                    Menu.Save(userTrainer);
                    break;

                case 4:
                    return;
                }
            }
        }
Пример #12
0
        public static void PurchaseItem(PokemonTrainer userTrainer, int itemChoiceIndex)
        {
            IItem chosenItem = ItemStore.Items[itemChoiceIndex];

            if (userTrainer.Money < chosenItem.Price)
            {
                Console.WriteLine("You don't have enough money.");
                return;
            }
            userTrainer.Money -= chosenItem.Price;
            Console.WriteLine($"Money: {userTrainer.Money}");
            userTrainer.Items.Add(chosenItem);
        }
Пример #13
0
        public static void FightWildPokemon(PokemonTrainer userTrainer)
        {
            int opponentLevel;

            do
            {
                Console.WriteLine("Your opponent level?");
                if (int.TryParse(Console.ReadLine(), out opponentLevel))
                {
                    if (opponentLevel >= 1 && opponentLevel <= 100)
                    {
                        Pokemon opponent = new Pokemon(Pokemons.GetRandomPokemon(), opponentLevel);
                        Console.WriteLine($"A wild {opponent.Name} (R:{opponent.Rarity}) appeared.");
                        Console.WriteLine($"{userTrainer.Name}: Alright, let's show 'em what we got, {userTrainer.PokemonOut.Name} (R:{userTrainer.PokemonOut.Rarity})");
                        Battle.FightPokemon(userTrainer, opponent);
                        break;
                    }
                }
            } while (true);
        }
Пример #14
0
        public static void PurchaseItem(PokemonTrainer userTrainer)
        {
            Console.WriteLine($"Money: {userTrainer.Money}");
            List <string> itemChoices = new List <string>();

            Console.WriteLine("----------------------");
            Console.WriteLine("Price   |   Name");
            Console.WriteLine("----------------------");

            foreach (IItem item in ItemStore.Items)
            {
                itemChoices.Add(String.Format("{0,-4} | {1,-4}", item.Price, item.Name));
            }
            int userInputIndex = Menu.GetUserInputIndex(itemChoices, true);

            if (userInputIndex == -1)
            {
                return;
            }
            ItemStore.PurchaseItem(userTrainer, userInputIndex);
        }
Пример #15
0
        public static void ChangePokemon(PokemonTrainer userTrainer, bool cancel)
        {
            List <string> userChoices = new List <string>();

            for (int i = 1; i < userTrainer.CaptivePokemons.Count; i++)
            {
                Pokemon pokemon = userTrainer.CaptivePokemons[i];
                userChoices.Add($"{pokemon.Name} - Level: {pokemon.Level}, Hp: {pokemon.Hp}");
            }

            int userInputIndex = Menu.GetUserInputIndex(userChoices, cancel);

            if (userInputIndex == -1)
            {
                return;
            }
            Console.WriteLine($"Come back {userTrainer.PokemonOut.Name}.");

            userTrainer.SwapPokemons(0, userInputIndex + 1);
            Console.WriteLine($"I choose you, {userTrainer.PokemonOut.Name}.");
        }
Пример #16
0
        public void Use(Pokemon opponent, PokemonTrainer userTrainer)
        {
            if (userTrainer.CaptivePokemons.Count >= 6)
            {
                Console.WriteLine("You have too many pokemons.");
                return;
            }
            userTrainer.Items.Remove(this);
            double captureProbability = (double)(this.Effectiveness * opponent.CaptureProbability);
            Random rand = new Random();

            if (captureProbability * this.Effectiveness >= rand.NextDouble())
            {
                userTrainer.CaptivePokemons.Add(opponent);
                Console.WriteLine($"{opponent.Name} fainted while trying to break out.");
                Console.WriteLine($"{opponent.Name} has been caught!");
                opponent.Hp = 0;
                return;
            }
            Console.WriteLine($"{opponent.Name} broke out!");
        }