示例#1
0
        public static void fightHeroAndDragon(Hero me, Dragon oponent)
        {
            // choose 2, 3
            Console.WriteLine("FIGHTING");
            int    round = 0;
            string ara   = "";

            StreamWriter writetext = new StreamWriter("write.txt");

            while (me.isDead() == false && oponent.isDead() == false)
            {
                round += 1;
                // oponent.randAttack();
                me.hitBy(oponent.randAttack());
                oponent.hitBy(me.randAttack());

                Console.WriteLine($"------------------------------- ROUND {round} -------------------------------");

                String meLost     = $"I lost {oponent.randAttack()} lives. \n";
                String meRamining = $"I have remaining {me.getHealth()} lives. \n";

                String oponentLost   = $" Oponent lost {oponent.randAttack()} lives. \n";
                String remainingLost = $"Oponent has remaining {oponent.getHealth()} lives. \n";

                Console.WriteLine(meLost);
                Console.WriteLine(meRamining);

                Console.WriteLine(oponentLost);
                Console.WriteLine(remainingLost);

                ara += meLost;
                ara += meRamining;

                ara += oponentLost;
                ara += remainingLost;


                //  string createText = "Hello and Welcome" + Environment.NewLine;
            }


            ara += "------------------------------------------ \n";

            if (oponent.isDead())
            {
                Console.WriteLine("I won!");
                ara += "I won";
            }
            else
            {
                Console.WriteLine("Oponent won!");
                ara += "Oponent won";
            }


            File.WriteAllText("results.txt", ara);
        }
示例#2
0
        /*-----------------------------------FIGHT BETWEEN DRAGON AND HERO-----------------------------------*/
        // data about the fight will be written in results.txt

        public static void fightHeroAndDragon(Hero me, Dragon oponent)
        {
            // choose 2, 3
            Console.WriteLine("FIGHTING");
            int    round = 0;
            string ara   = "";


            while (me.isDead() == false && oponent.isDead() == false)
            {
                round += 1;
                // oponent.randAttack();
                me.hitBy(oponent.randAttack());
                oponent.hitBy(me.randDefense());

                Console.WriteLine($"------------------------------- ROUND {round} -------------------------------");

                string meLost     = $"I lost {oponent.randAttack()} lives. \n";
                string meRamining = $"I have remaining {me.getHealth()} lives. \n";

                string oponentLost   = $" Oponent lost {me.randDefense()} lives. \n";
                string remainingLost = $"Oponent has remaining {oponent.getHealth()} lives. \n";

                Console.WriteLine(meLost);
                Console.WriteLine(meRamining);

                Console.WriteLine(oponentLost);
                Console.WriteLine(remainingLost);

                ara += meLost;
                ara += meRamining;

                ara += oponentLost;
                ara += remainingLost;
            }


            ara += "------------------------------------------ \n";

            if (oponent.isDead())
            {
                Console.WriteLine("I won!");
                ara += "I won";
            }
            else
            {
                Console.WriteLine("Oponent won!");
                ara += "Oponent won";
            }


            File.WriteAllText("results.txt", ara); // WRITE TO TEXT FILE
        }
示例#3
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()} ");
                        }
                    }
                }
            }
        }