Beispiel #1
0
        public Warrior RunSimulation()
        {
            Warrior currentGood = null, currentEvil = null;

            while ((currentGood != null || (currentGood = GetRandomWarrior(_goods)) != null) && (currentEvil != null || (currentEvil = GetRandomWarrior(_evils)) != null))
            {
                if (currentGood.IsStrongerThan(currentEvil))
                {
                    currentGood.Power -= currentEvil.Power;
                    if (currentGood.Power <= 0)
                    {
                        currentGood = null;
                    }
                    currentEvil = null;
                }
                else if (currentEvil.IsStrongerThan(currentGood))
                {
                    currentEvil.Power -= currentGood.Power;
                    if (currentEvil.Power <= 0)
                    {
                        currentEvil = null;
                    }
                    currentGood = null;
                }
                else
                {
                    currentGood = null;
                    currentEvil = null;
                }
            }

            return(currentGood ?? currentEvil);
        }
        public Warrior RunSimulation()
        {
            Warrior light = null, dark = null;

            while ((light = LightSide.GetWarrior()) != null &&
                   (dark = DarkSide.GetWarrior()) != null)
            {
                light.PreCombatEffect();
                dark.PreCombatEffect();
                if (light.IsStrongerThan(dark))
                {
                    light.DecreasePower(dark.Power);
                    if (light.Power <= 0)
                    {
                        LightSide.KillWarrior();
                    }
                    DarkSide.KillWarrior();
                }
                else if (dark.IsStrongerThan(light))
                {
                    dark.DecreasePower(light.Power);
                    if (dark.Power <= 0)
                    {
                        DarkSide.KillWarrior();
                    }
                    LightSide.KillWarrior();
                }
                else
                {
                    LightSide.KillWarrior();
                    DarkSide.KillWarrior();
                }
                light.PostCombatEffect();
                dark.PostCombatEffect();
            }

            return(light ?? dark);
        }