Exemplo n.º 1
0
        public static string Fight(IFighter f1, IFighter f2)
        {
            while (!f1.HasEscaped() && !f2.HasEscaped() && (f1.DefenseLeft > 0) && (f2.DefenseLeft > 0))
            {
                // Første fighter henter attack
                int attack = f1.Attack();
                // Anden fighter skal forsvare sig
                f2.Defend(attack);
                Console.WriteLine("Player 2 is hit for " + attack + ": " + f2.DefenseLeft + "HP left");
                // Anden fighter henter attack
                attack = f2.Attack();
                //Første fighter skal forsvare sig
                f1.Defend(attack);
                Console.WriteLine("Player 1 is hit for " + attack + ": " + f1.DefenseLeft + "HP left");
            }

            string winner = "Draw";

            // kampen er afsluttet
            if ((f1.DefenseLeft > 0) && (!f1.HasEscaped()))
            {
                winner = "f1 vandt";
            }

            if ((f2.DefenseLeft > 0) && (!f2.HasEscaped()))
            {
                winner = "f2 vandt";
            }

            // Hvis der returneres null, så har kampen været jævnbyrdig
            return(winner);
        }
Exemplo n.º 2
0
        public static IFighter Fight(IFighter f1, IFighter f2)
        {
            while (!f1.HasEscaped() && !f2.HasEscaped() && f1.DefenseLeft > 0 && f2.DefenseLeft > 0)
            {
                // Første fighter henter attack
                int attack = f1.Attack();
                // Anden fighter skal forsvare sig
                f2.Defend(attack);
                // Anden fighter henter attack
                attack = f2.Attack();
                // Første fighter skal forsvare sig
                f1.Defend(attack);
            }

            IFighter winner = null;


            // kampen er afsluttet
            if ((f1.DefenseLeft > 0) && (!f1.HasEscaped()))
            {
                winner = f1;
            }

            if ((f2.DefenseLeft > 0) && (!f2.HasEscaped()))
            {
                winner = f2;
            }

            // Hvis der returneres null, så har kampen været jævnbyrdig
            return(winner);
        }
        public void Attack()
        {
            var attack = _fighter.Attack();

            LogMessages(attack.Messages);

            EnemyFighterViewModel?.Defend(attack);
        }
        public void Attack()
        {
            var attack = _fighter.Attack();

            LogMessages(attack.Messages);

            if (EnemyFighterViewModel != null)
            {
                EnemyFighterViewModel.Defend(attack);
            }
        }
Exemplo n.º 5
0
        public static IFighter Fight(IFighter f1, IFighter f2)
        {
            while ((!f1.HasEscaped() && !f2.HasEscaped()) && ((f1.DefenseLeft > 0) && (f2.DefenseLeft > 0)))
            {
                // Første fighter henter attack
                int attack = f1.Attack();
                Console.WriteLine("Whiteknight attacks for {0}", attack);
                // Anden fighter skal forsvare sig
                f2.Defend(attack);
                Console.WriteLine("BlackKnight HP {0}", f2.DefenseLeft);
                // Anden fighter henter attack
                attack = f2.Attack();
                Console.WriteLine("BlackKnight attacks for {0}", attack);

                // Første fighter skal forsvare sig
                f1.Defend(attack);
                Console.WriteLine("Whiteknight HP {0}", f1.DefenseLeft);
            }
            if (f1.HasEscaped())
            {
                Console.WriteLine("WhiteKnight cowardly fled from combat");
            }
            else if (f2.HasEscaped())
            {
                Console.WriteLine("BlackKnight cowardly fled from combat");
            }
            else if (f1.DefenseLeft <= 0)
            {
                Console.WriteLine("WhiteKnight was slain in combat");
            }
            else if (f1.DefenseLeft <= 0)
            {
                Console.WriteLine("BlackKnight was slain in combat");
            }

            IFighter winner = null;

            // kampen er afsluttet
            if ((f1.DefenseLeft > 0) && (!f1.HasEscaped()))
            {
                winner = f1;
                Console.WriteLine("Whiteknight wins");
            }

            if ((f2.DefenseLeft > 0) && (!f2.HasEscaped()))
            {
                winner = f2;

                Console.WriteLine("Whiteknight wins");
            }

            // Hvis der returneres null, så har kampen været jævnbyrdig
            return(winner);
        }
Exemplo n.º 6
0
        /// <summary>
        /// A really poor simulation
        /// </summary>
        public void BeginSimulation()
        {
            while (teamOneFighters.Any() && teamTwoFighters.Any())
            {
                IFighter teamOneFighter = teamOneFighters.First();
                IFighter teamTwoFighter = teamTwoFighters.First();
                teamOneFighter.Attack(teamTwoFighter);
                if (teamTwoFighter.IsAlive)
                {
                    Console.WriteLine($"{teamTwoFighter.Class} from {TeamTwo} lives with {teamTwoFighter.HealthPoints}.");
                }
                else
                {
                    Console.WriteLine($"{teamTwoFighter.Class} from {TeamTwo} dies.");
                    teamTwoFighters.Remove(teamTwoFighter);
                }

                teamTwoFighter.Attack(teamOneFighter);
                if (teamOneFighter.IsAlive)
                {
                    Console.WriteLine($"{teamOneFighter.Class} from {TeamOne} lives with {teamOneFighter.HealthPoints}.");
                }
                else
                {
                    Console.WriteLine($"{teamOneFighter.Class} from {TeamOne} dies.");
                    teamOneFighters.Remove(teamOneFighter);
                }
            }

            if (teamOneFighters.Any())
            {
                Console.WriteLine($"{TeamOne} wins !!");
            }
            if (teamTwoFighters.Any())
            {
                Console.WriteLine($"{TeamTwo} wins !!");
            }
        }
Exemplo n.º 7
0
 public virtual Attack Attack()
 {
     return(fighter.Attack());
 }
Exemplo n.º 8
0
 public void Execute()
 {
     owner.Attack(target);
 }
Exemplo n.º 9
0
 public virtual Attack Attack()
 {
     return(_wrappee.Attack());
 }