Exemple #1
0
        public static void Main(string[] args)
        {
            int   round = 0;
            Audit ad    = new Audit();

            Sword  sword  = new Sword("NiceSword", 130);
            Shield shield = new Shield("NiceShield", 130);

            List <Base> characters = new List <Base>()
            {
                new Hero(sword, shield, "Filip", 100, 100, 100),
                new Hero(sword, shield, "Jana", 100, 100, 100),
                new Hero(sword, shield, "Jana", 100, 100, 100),
                new Dragon("Max", 100, 100, 100)
            };

            double avg = ad.averagePower(characters);

            Console.WriteLine("Average power of characters is " + avg);


            var count = 0;



            // someAlive(count)
            while (RealSomeAlive(characters))
            {
                count += 1;



                for (var i = 0; i < characters.Count - 1; i++)
                {
                    object first            = convert(characters[i]);
                    object second           = convert(characters[i + 1]);
                    double firstAttackValue = 0;

                    round += 1;
                    Console.WriteLine($"=============================ROUND {round} ===========================");

                    if (first is Hero)
                    {
                        firstAttackValue = ((Hero)first).randAttack();
                        Console.WriteLine($"Hero attacked Dragon with {firstAttackValue}");
                    }

                    if (second is Dragon)
                    {
                        //  Console.WriteLine($"Dragon {second.GetType()}");
                        Dragon dra = ((Dragon)second);
                        dra.hitBy(firstAttackValue);
                        Console.WriteLine($"Dragon lost {firstAttackValue} health and has {dra.getHealth()} lives");



                        //2nd character strikes back
                        double attack = dra.randAttack();

                        if (first is Hero)
                        {
                            Hero hra = ((Hero)first);
                            hra.hitBy(attack);
                            Console.WriteLine($"Dragin strikes back by {attack} and hero has  {hra.getHealth()} ");
                        }
                    }
                }
            }
        }