Example #1
0
        static string name(Base character)
        {
            if (character is Dragon)
            {
                Dragon drg = (Dragon)(character);
                return($" Dragon {drg.getName()}");
            }

            if (character is Hero)
            {
                Hero hrg = (Hero)(character);
                return($" Hero {hrg.getName()}");
            }

            return("empty");
        }
Example #2
0
        public bool allHaveGraterThaFourthOfAverage(List <Base> b)
        {
            // bool all = false;



            double avga = averagePower(b);


            int count = 0;

            for (var i = 0; i < b.Count; i++)
            {
                object conv = b[i];


                if (conv is Dragon)
                {
                    Dragon conva = (Dragon)(conv);

                    if (conva.maxDamage > avga / 4)
                    {
                        //res += "\n" + conva.getName();
                        count += 1;
                        // Console.WriteLine(conva.getName());
                    }
                }

                if (conv is Hero)
                {
                    Hero conva = (Hero)(conv);

                    if (conva.maxDamage > avga / 4)
                    {
                        count += 1;
                        // res += "\n" + conva.getName();
                        // Console.WriteLine(conva.getName());
                    }
                }
            }



            return(count == b.Count);
        }
Example #3
0
        public static void fight(Base ME, Base OPONENT)
        {
            // ME is Dragon and  oponent is Hero



            if ((ME is Hero) && (OPONENT is Dragon))
            {
                Hero   me      = ((Hero)ME);
                Dragon oponent = ((Dragon)OPONENT);
                fightHeroAndDragon(me, oponent);
            }
            else if ((ME is Hero) && (OPONENT is Hero))
            {
                Hero me      = ((Hero)ME);
                Hero oponent = ((Hero)OPONENT);
                fightHero(me, oponent);
            }
        }
Example #4
0
        /* TO MAIN
         *
         * // var c = new Counter();
         * // c.ThresholdReached += c_ThresholdReached;
         *
         * // provide remaining implementation for the class
         */



        public static void listCharacters(List <Base> characters)
        {
            Console.WriteLine("----------------------------------- CHARACTERS -----------------------------------");
            for (var i = 0; i < characters.Count; i++)
            {
                object obj = convert(characters[i]);

                if (obj is Dragon)
                {
                    Dragon dragon = (Dragon)(obj);
                    Console.WriteLine($"Dragon {dragon.getName()} ");
                }

                if (obj is Hero)
                {
                    Hero hero = (Hero)(obj);
                    Console.WriteLine($"Hero {hero.getName()} ");
                }
            }
        }
Example #5
0
        public override int chooseOponent(int oponentIndex, List <Base> b)
        {
            Console.WriteLine($"Hero chose oponent at index {oponentIndex}");
            object conv = b[oponentIndex];

            Adder a = new Adder();

            a.OnShouldFireEvent += () => // oponent name in Event handler
            {
                if (conv is Dragon)
                {
                    Dragon he = (Dragon)(conv);
                    Console.WriteLine("His name in EVENT handler is " + he.getName());
                }
                else if (conv is Hero)
                {
                    // Get his name
                    Hero he = (Hero)(conv);
                    Console.WriteLine("His name in EVENT handler is " + he.getName());
                }
            };

            int iAnswer = a.Add();

            // Hero can attack other Heroes, but Dragon cannot attack other dragons
            if (conv is Dragon)
            {
                Dragon he = (Dragon)(conv);
                return(oponentIndex);
            }
            else if (conv is Hero)
            {
                // Get his name
                Hero he = (Hero)(conv);
                return(oponentIndex);
            }
            return(-1);
        }
Example #6
0
        /* public static List<Base> SortUsingCompareTo (List<Base> characters){
         *
         *  // characters.Sort();
         *     try
         *     {
         *         characters.Sort();
         *     }
         *     catch (Exception e)
         *     {
         *         Console.WriteLine("UIGIUG");
         *         Console.WriteLine(e);
         *     }
         *
         *
         *  // return characters.Sort();
         *
         * }*/



        public static void Main(string[] args)
        {
            int round = 0;

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

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

            dataManipulation(characters);
            listCharacters(characters);


            // List<Base> usingCompareTo = SortUsingCompareTo(characters);


            characters.Sort(); // SORTED USING CompareTo
                               // characters.reverse(Sort()); // SORTED USING CompareTo
                               //  List<Base> usingCompareTo =



            Console.WriteLine("Strongest to least strong");

            // Strongest to least strong
            for (var i = 0; i < characters.Count; i++)
            {
                Base d = convert(characters[i]);
                if (d is Dragon)
                {
                    Dragon dra = ((Dragon)d);
                    Console.WriteLine(dra.getName());
                }

                if (d is Hero)
                {
                    Hero hero = ((Hero)d);
                    Console.WriteLine(hero.getName());
                }
            }


            // 97% :)
            Console.WriteLine("Least strong to strongest.");
            // Least Strong to Strongest
            for (var i = characters.Count - 1; i > 0; i--)
            {
                Base d = convert(characters[i]);
                if (d is Dragon)
                {
                    Dragon dra = ((Dragon)d);
                    Console.WriteLine(dra.getName());
                }

                if (d is Hero)
                {
                    Hero hero = ((Hero)d);
                    Console.WriteLine(hero.getName());
                }
            }



            Console.WriteLine("Choose your character (enter index)");
            int aidx = int.Parse(Console.ReadLine());


            object ME      = characters[0];
            object OPONENT = characters[0];

            Console.WriteLine("You character is " + name(characters[aidx]));
            object o = convert(characters[aidx]);

            ME = characters[aidx];

            if (o is Dragon)
            {
                Dragon dra = ((Dragon)o);

                Console.WriteLine("Choose his oponent: (enter index)");
                int bidx = int.Parse(Console.ReadLine());
                int ipo  = dra.chooseOponent(bidx, characters);
                Console.WriteLine("OPONENT IS" + name(characters[ipo]));
                OPONENT = characters[ipo];
            }
            else
            {
                Hero dra = ((Hero)o);

                Console.WriteLine("Choose his oponent: (enter index)");
                int bidx = int.Parse(Console.ReadLine());
                int ipo  = dra.chooseOponent(bidx, characters);
                Console.WriteLine("OPONENT IS" + name(characters[ipo]));
                OPONENT = characters[ipo];
            }



            /*-----------------------------------AT THIS POINT, I WANT 2 CHARACTERS FIGHTING-----------------------------------*/



            fight(((Base)ME), ((Base)OPONENT));



            //  Console.WriteLine($"You have selected indexes A: {aidx}  B: {bidx}");



            // 1 - select

            // 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()} ");
             *           }
             *       }
             *   }
             * }*/
        }
Example #7
0
        /*----------------------------------------------------------------------------------------------- MAIN -----------------------------------------------------------------------------------------------*/
        public static void Main(string[] args)
        {
            Sword  sword  = new Sword("NiceSword", 1, 130);
            Shield shield = new Shield("NiceShield", 1, 130);

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


            List <Base> copyToSort = characters.ToList(); // make a copy, so our original array stays intact

            dataManipulation(characters);
            listCharacters(characters);

            copyToSort.Sort(); // SORTED USING CompareTo


            Console.WriteLine("Strongest to least strong");

            // Strongest to least strong
            for (var i = 0; i < copyToSort.Count; i++)
            {
                Base d = convert(copyToSort[i]);
                if (d is Dragon)
                {
                    Dragon dra = ((Dragon)d);
                    Console.WriteLine(dra.getName());
                }

                if (d is Hero)
                {
                    Hero hero = ((Hero)d);
                    Console.WriteLine(hero.getName());
                }
            }

            Console.WriteLine("Least strong to strongest.");

            // Least Strong to Strongest
            for (var i = copyToSort.Count - 1; i >= 0; i--)
            {
                Base d = convert(copyToSort[i]);
                if (d is Dragon)
                {
                    Dragon dra = ((Dragon)d);
                    Console.WriteLine(dra.getName());
                }

                if (d is Hero)
                {
                    Hero hero = ((Hero)d);
                    Console.WriteLine(hero.getName());
                }
            }



            Console.WriteLine("Choose your character (enter index)");
            int aidx = int.Parse(Console.ReadLine());

            object ME      = characters[0];
            object OPONENT = characters[0];

            Console.WriteLine("You character is " + name(characters[aidx]));
            object o = convert(characters[aidx]);

            ME = characters[aidx];

            if (o is Dragon)
            {
                Dragon dra = ((Dragon)o);

                Console.WriteLine("Choose his oponent: (enter index)");
                int bidx = int.Parse(Console.ReadLine());
                int ipo  = dra.chooseOponent(bidx, characters);
                Console.WriteLine("OPONENT IS" + name(characters[ipo]));
                OPONENT = characters[ipo];
            }
            else
            {
                Hero dra = ((Hero)o);

                Console.WriteLine("Choose his oponent: (enter index)");
                int bidx = int.Parse(Console.ReadLine());
                int ipo  = dra.chooseOponent(bidx, characters);
                Console.WriteLine("OPONENT IS" + name(characters[ipo]));
                OPONENT = characters[ipo];
            }



            /*-----------------------------------AT THIS POINT, 2 CHARACTERS FIGHTING-----------------------------------*/
            fight(((Base)ME), ((Base)OPONENT));
        }
Example #8
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()} ");
                        }
                    }
                }
            }
        }