Esempio n. 1
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()} ");
             *           }
             *       }
             *   }
             * }*/
        }
Esempio n. 2
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));
        }