コード例 #1
0
ファイル: Program.cs プロジェクト: Gui-Alves/Pokemon
        static void Main(string[] args)
        {
            List <Pokemons> escolha1 = new List <Pokemons>();
            List <Pokemons> escolha2 = new List <Pokemons>();
            List <Trainers> t        = new List <Trainers>();
            Trainers        p1       = new Trainers();
            Trainers        p2       = new Trainers();

            t.Add(p1); t.Add(p2);
            int resp;

            int[] battlePokemon = new int[2];
            bool  battle        = true;

            prepararPokemons();
            Console.WriteLine("Digite o nome do jogador 1:");
            t[0].Nome = Console.ReadLine();
            Console.Clear();
            Console.WriteLine("Digite o nome do jogador 2:");
            t[1].Nome = Console.ReadLine();
            Console.Clear();

            for (int i = 0; i < 6; i++)
            {
                if (i > 0)
                {
                    Console.WriteLine($"Pokemons de {t[0].Nome}:");
                    t[0].Pokemons.ForEach(p => Console.WriteLine($"{p.Nome}"));
                    Console.WriteLine();
                    if (i > 1)
                    {
                        Console.WriteLine($"Pokemons de {t[1].Nome}:");
                        t[1].Pokemons.ForEach(p => Console.WriteLine($"{p.Nome}"));
                        Console.WriteLine();
                    }
                }
                Console.WriteLine($"{t[i % 2].Nome}, escolha um pokemon: ");
                pokemons.ForEach(p => Console.WriteLine($"{pokemons.IndexOf(p) + 1,-2}- {p.Nome,-13} | Dano: {p.Dano,-2} | Def: {p.Defesa,-2} | Vida: {p.Vida}"));
                resp = Convert.ToInt32(Console.ReadLine());
                if (i % 2 == 0)
                {
                    escolha1.Add(pokemons[resp - 1]);
                    t[0].Pokemons = escolha1;
                }
                else
                {
                    escolha2.Add(pokemons[resp - 1]);
                    t[1].Pokemons = escolha2;
                }

                pokemons.Remove(pokemons[resp - 1]);

                Console.Clear();
            }

            while (battle)
            {
                for (int i = 0; i < 2; i++)
                {
                    Console.Clear();
                    Console.WriteLine($"Pokemons de {t[0].Nome}:");
                    t[0].Pokemons.ForEach(p => Console.WriteLine($"{t[0].Pokemons.IndexOf(p) + 1} - {p.Nome,-13} | Dano: {p.Dano,-2} | Def: {p.Defesa,-2} | Vida: {p.Vida}"));
                    Console.WriteLine();
                    Console.WriteLine($"Pokemons de {t[1].Nome}:");
                    t[1].Pokemons.ForEach(p => Console.WriteLine($"{t[1].Pokemons.IndexOf(p) + 1} - {p.Nome,-13} | Dano: {p.Dano,-2} | Def: {p.Defesa,-2} | Vida: {p.Vida}"));
                    Console.WriteLine();
                    Console.WriteLine($"{t[i % 2].Nome}, escolha um pokemon para batalhar:");
                    battlePokemon[i % 2] = Convert.ToInt32(Console.ReadLine()) - 1;
                }

                Console.WriteLine($"{t[0].Pokemons[battlePokemon[0]].Nome} \n   VS\n{t[1].Pokemons[battlePokemon[1]].Nome} \n\n");

                if (t[0].Pokemons[battlePokemon[0]].Dano > t[1].Pokemons[battlePokemon[1]].Defesa)
                {
                    t[1].Pokemons[battlePokemon[1]].Vida -= t[0].Pokemons[battlePokemon[0]].Dano - t[1].Pokemons[battlePokemon[1]].Defesa;
                    Console.WriteLine($"{t[0].Pokemons[battlePokemon[0]].Nome} acerta o ataque!");
                }
                if (t[1].Pokemons[battlePokemon[1]].Dano > t[0].Pokemons[battlePokemon[0]].Defesa)
                {
                    t[0].Pokemons[battlePokemon[0]].Vida -= t[1].Pokemons[battlePokemon[1]].Dano - t[0].Pokemons[battlePokemon[0]].Defesa;
                    Console.WriteLine($"{t[1].Pokemons[battlePokemon[1]].Nome} acerta o ataque!");
                }

                if (t[0].Pokemons[battlePokemon[0]].Vida <= 0)
                {
                    Console.WriteLine($"{t[0].Pokemons[battlePokemon[0]].Nome} está fora de combate!");
                    t[0].Pokemons.RemoveAt(battlePokemon[0]);
                }

                if (t[1].Pokemons[battlePokemon[1]].Vida <= 0)
                {
                    Console.WriteLine($"{t[1].Pokemons[battlePokemon[1]].Nome} está fora de combate!");
                    t[1].Pokemons.RemoveAt(battlePokemon[1]);
                }
                Console.ReadKey();
                Console.Clear();
                if (!t[0].Pokemons.Any())
                {
                    Console.WriteLine($"{t[1].Nome} venceu a partida!");
                    battle = false;
                }

                if (!t[1].Pokemons.Any())
                {
                    Console.WriteLine($"{t[0].Nome} venceu a partida!");
                    battle = false;
                }
                Console.ReadKey();
            }
            Console.ReadKey();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //Func<Trainers,bool> chekHealth = x => x.Pokemons.Where(x => x.Health>0) ;

            Dictionary <string, Trainers> trainersList = new Dictionary <string, Trainers>();

            while (true)
            {
                string[] input = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string trainerName = input[0];
                if (trainerName == "Tournament")
                {
                    break;
                }
                string pokemonName    = input[1];
                string pokemonElement = input[2];
                int    pokemonHealth  = int.Parse(input[3]);

                if (!trainersList.ContainsKey(trainerName))
                {
                    var pokemon = new Pokemon(pokemonName, pokemonHealth, pokemonElement);

                    var trainer = new Trainers(trainerName);
                    trainer.Pokemons.Add(pokemon);
                    trainersList[trainerName] = trainer;
                }
                else
                {
                    var pokemon = new Pokemon(pokemonName, pokemonHealth, pokemonElement);
                    trainersList[trainerName].Pokemons.Add(pokemon);
                }
            }


            while (true)
            {
                string input = Console.ReadLine();

                if (input == "End")
                {
                    break;
                }
                bool hasElement = false;


                chek(trainersList, input, hasElement);
                hasElement = false;
            }

            //var result = trainersList.SelectMany(x => x.Value.Pokemons.Where(c => c.health > 0));



            foreach (var item in trainersList.OrderByDescending(x => x.Value.NumbersOfBadges))
            {
                int count = 0;
                foreach (var item2 in item.Value.Pokemons.Where(x => x.Health > 0))
                {
                    count++;
                }

                Console.WriteLine($"{item.Value.Name} {item.Value.NumbersOfBadges} {count}");
                //foreach (var item2 in item.Value.Pokemons)
                //{
                //    if(item2.Health <= 0)
                //    {

                //    }
                //}
            }
        }