Пример #1
0
        public Ship Attack(BattleFleet defender)
        {
            Ship shipB = _getEnemy(defender);

            if (shipB == null)
            {
                return(null);
            }

            float damage = 0;

            foreach (Weapon weapon in OffensiveWeapons)
            {
                damage += weapon.Fire();
            }
            shipB.Defend(this, damage);
            return(shipB);
        }
Пример #2
0
        public void Attack(BattleFleet defender)
        {
            for (int j = 0; j < 10; j++)
            {
                Shuffle();
                defender.Shuffle();

                for (int i = 0; i < Math.Max(Count, defender.Count); i++)
                {
                    if (i < Count)
                    {
                        Ship shipA = this[i];
                        shipA.Reload();
                        Ship shipB = shipA.Attack(defender);
                        if (shipA.HullStrength == 0)
                        {
                            Remove(shipA);
                            WriteDestroyed(shipA);
                        }
                        if (shipB?.HullStrength == 0)
                        {
                            defender.Remove(shipB);
                            WriteDestroyed(shipB);
                        }
                    }
                    if (i < defender.Count)
                    {
                        Ship shipB = defender[i];
                        shipB.Reload();
                        Ship shipA = shipB.Attack(this);
                        if (shipB.HullStrength == 0)
                        {
                            Remove(shipB);
                            WriteDestroyed(shipB);
                        }
                        if (shipA?.HullStrength == 0)
                        {
                            defender.Remove(shipA);
                            WriteDestroyed(shipA);
                        }
                    }
                }
            }
        }
Пример #3
0
        private Ship _getEnemy(BattleFleet defender)
        {
            Ship shipB = null;

            switch (Model.Class)
            {
            case ShipClass.Interceptor:
            case ShipClass.Corvette:
            case ShipClass.Frigate:
                if (!defender.TryGetFighter(out shipB))
                {
                    if (!defender.TryGetCruiser(out shipB))
                    {
                        defender.TryGetDestroyer(out shipB);
                    }
                }
                break;

            case ShipClass.Fighter:
            case ShipClass.LightCruiser:
                if (!defender.TryGetCruiser(out shipB))
                {
                    if (!defender.TryGetFighter(out shipB))
                    {
                        defender.TryGetDestroyer(out shipB);
                    }
                }
                break;

            case ShipClass.HeavyCruiser:
            case ShipClass.Destroyer:
            case ShipClass.Battlecruiser:
            case ShipClass.Dreadnought:
                if (!defender.TryGetDestroyer(out shipB))
                {
                    if (!defender.TryGetCruiser(out shipB))
                    {
                        defender.TryGetFighter(out shipB);
                    }
                }
                break;
            }
            return(shipB);
        }