public static void Main(string[] args)
        {
            //var battleship = Battleship.CreateBattleShip("Raven");

            var factory = new ShipFactory <Battleship>();

            var raven    = factory.CreateShip(Battleships.Raven);
            var dominix  = factory.CreateShip(Battleships.Dominix);
            var rokh     = factory.CreateShip(Battleships.Rokh);
            var scorpion = factory.CreateShip(Battleships.Scorpion);

            var canon      = new Weapon(Weapons.Cannon, WeaponGrades.Large);
            var projectile = new Weapon(Weapons.Projectile, WeaponGrades.Large);
            var laser      = new Weapon(Weapons.Laser, WeaponGrades.Large);
            var missile    = new Weapon(Weapons.Missile, WeaponGrades.Large);

            raven.InstallWeapon(canon, 1);
            dominix.InstallWeapon(projectile, 1);
            rokh.InstallWeapon(laser, 1);
            scorpion.InstallWeapon(missile, 1);

            var attackingPlanetOffensiveFormation = new BattleFormation("ap of");
            var attackingPlanetDefensiveFormation = new BattleFormation("ap df");
            var defensivePlanetOffensiveFormation = new BattleFormation("dp of");
            var defensivePlanetDefensiveFormation = new BattleFormation("dp df");

            attackingPlanetOffensiveFormation.SetFormationRow(raven, 100, 1);
            attackingPlanetDefensiveFormation.SetFormationRow(dominix, 100, 1);
            defensivePlanetOffensiveFormation.SetFormationRow(raven, 100, 1);
            defensivePlanetDefensiveFormation.SetFormationRow(raven, 100, 1);


            var attackingPlanetOffensiveFormationGeneral = new General();
            var attackingPlanetDefensiveFormationGeneral = new General();
            var defensivePlanetOffensiveFormationGeneral = new General();
            var defensivePlanetDefensiveFormationGeneral = new General();

            attackingPlanetOffensiveFormation.SetGeneral(attackingPlanetOffensiveFormationGeneral);
            attackingPlanetDefensiveFormation.SetGeneral(attackingPlanetDefensiveFormationGeneral);
            defensivePlanetDefensiveFormation.SetGeneral(defensivePlanetDefensiveFormationGeneral);
            defensivePlanetOffensiveFormation.SetGeneral(defensivePlanetOffensiveFormationGeneral);

            var attackingPlanet = new Planet(Planets.Pandora);
            var defensivePlanet = new Planet(Planets.Desert);

            attackingPlanet.AddFormation(attackingPlanetOffensiveFormation);
            attackingPlanet.AddFormation(attackingPlanetDefensiveFormation);
            defensivePlanet.AddFormation(defensivePlanetOffensiveFormation);
            defensivePlanet.AddFormation(defensivePlanetDefensiveFormation);

            attackingPlanet.ActivateFormation(attackingPlanetOffensiveFormation, BattleFormationType.Offensive);
            attackingPlanet.ActivateFormation(attackingPlanetDefensiveFormation, BattleFormationType.Defensive);
            defensivePlanet.ActivateFormation(defensivePlanetOffensiveFormation, BattleFormationType.Offensive);
            defensivePlanet.ActivateFormation(defensivePlanetDefensiveFormation, BattleFormationType.Defensive);

            BattleSimulator.CalculateBattleResult(attackingPlanet, defensivePlanet);
        }
Exemple #2
0
        public void CheckStatisGravityNotAllowed(DamageTypeEnum weapon1Type, DamageTypeEnum weapon2Type)
        {
            var ship = ShipFactory.CreateShip();
            var wing = WingFactory.CreateWing();

            var weapon1 = WeaponFactory.CreateWeapon();

            weapon1.Setup(w => w.DamageType).Returns(weapon1Type);
            var weapon2 = WeaponFactory.CreateWeapon();

            weapon2.Setup(w => w.DamageType).Returns(weapon2Type);

            wing.Setup(w => w.NumberOfHardpoints).Returns(2);
            wing.Setup(w => w.Hardpoint).Returns((new[] { weapon1.Object, weapon2.Object }).ToList());

            ship.Setup(s => s.Wings).Returns((new[] { wing.Object }).ToList());

            var valid = Validate(ship, "ForceStress");

            if ((weapon1Type == DamageTypeEnum.Statis || weapon2Type == DamageTypeEnum.Statis) && (weapon1Type == DamageTypeEnum.Gravity || weapon2Type == DamageTypeEnum.Gravity) && weapon1Type != weapon2Type)
            {
                Assert.False(valid);
            }
            else
            {
                Assert.True(valid);
            }
        }
Exemple #3
0
        public void TestShipCreation()
        {
            ComponentDesign engineDesign;

            _engineSD    = _game.StaticData.ComponentTemplates[new Guid("E76BD999-ECD7-4511-AD41-6D0C59CA97E6")];
            engineDesign = GenericComponentFactory.StaticToDesign(_engineSD, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData);
            engineDesign.ComponentDesignAbilities[0].SetValueFromInput(5); //size = 25 power.
            //engineDesignDB.ComponentDesignAbilities[1]
            _engineComponent = GenericComponentFactory.DesignToDesignEntity(_game, _faction, engineDesign);

            _shipClass = ShipFactory.CreateNewShipClass(_game, _faction, "Ob'enn dropship");
            EntityManipulation.AddComponentToEntity(_shipClass, _engineComponent);
            EntityManipulation.AddComponentToEntity(_shipClass, _engineComponent);

            Vector4 pos = new Vector4(0, 0, 0, 0);

            _ship = ShipFactory.CreateShip(_shipClass, _starSystem.SystemManager, _faction, pos, _starSystem, "Serial Peacemaker");
            PropulsionDB propulsion = _ship.GetDataBlob <PropulsionDB>();
            ShipInfoDB   shipInfo   = _ship.GetDataBlob <ShipInfoDB>();

            //Change in component cloning makes the next line's assumption untrue
            //Assert.True(_ship.GetDataBlob<ComponentInstancesDB>().SpecificInstances.ContainsKey(_engineComponent));
            Assert.AreEqual(50, propulsion.TotalEnginePower);
            Assert.AreEqual(ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, _ship.GetDataBlob <ShipInfoDB>().Tonnage), propulsion.MaximumSpeed);

            EntityManipulation.AddComponentToEntity(_ship, _engineComponent);
            Assert.AreEqual(75, propulsion.TotalEnginePower);
            Assert.AreEqual(ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, _ship.GetDataBlob <ShipInfoDB>().Tonnage), propulsion.MaximumSpeed);
        }
Exemple #4
0
        public override void Execute(string[] commandArgs)
        {
            //create {shipType} {shipName} {starSystem} {enhancement1 enhancements2 ...}

            StarshipType starshipType = CastStringToStarshipType(commandArgs[1]);
            string       starshipName = commandArgs[2];

            if (GetStarshipByName(starshipName) != null)
            {
                Console.WriteLine(Messages.DuplicateShipName);
            }


            string starshipLocation = commandArgs[3];

            var ship = new ShipFactory();

            IStarship starship = ship.CreateShip(starshipType, starshipName, this.GameEngine.Galaxy.GetStarSystemByName(starshipLocation));

            if (commandArgs.Length > 3)
            {
                var enhancementFactory = new EnhancementFactory();
                for (int i = 4; i < commandArgs.Length; i++)
                {
                    starship.AddEnhancement(
                        enhancementFactory
                        .Create(CastStringToEnhancementType(commandArgs[i])));
                }
            }

            this.GameEngine.Starships.Add(starship);

            Console.WriteLine(Messages.CreatedShip, starshipType, starshipName);
        }
Exemple #5
0
 public void initPlayer()
 {
     Player    = ShipFactory.CreateShip("Falcon", window.Size.X / 4, window.Size.Y / 2, world);
     input.P   = Player;
     playerHud = new HUD(Player);
     Player.body.CollisionCategories = Category.Cat6;
 }
Exemple #6
0
        public void CheckStatisShipWeight()
        {
            var ship   = ShipFactory.CreateShip();
            var engine = EngineFactory.CreateEngine();
            var wing1  = WingFactory.CreateWing();
            var wing2  = WingFactory.CreateWing();

            wing1.Setup(w => w.Weight).Returns(5);
            wing2.Setup(w => w.Weight).Returns(10);

            var weapon1 = WeaponFactory.CreateWeapon();

            weapon1.Setup(w => w.Weight).Returns(15);
            weapon1.Setup(w => w.DamageType).Returns(DamageTypeEnum.Statis);
            var weapon2 = WeaponFactory.CreateWeapon();

            weapon2.Setup(w => w.Weight).Returns(20);
            weapon2.Setup(w => w.DamageType).Returns(DamageTypeEnum.Statis);

            wing1.Setup(w => w.Hardpoint).Returns((new[] { weapon1.Object }).ToList());
            wing2.Setup(w => w.Hardpoint).Returns((new[] { weapon2.Object }).ToList());

            engine.Setup(e => e.Weight).Returns(25);

            ship.Setup(s => s.Engine).Returns(engine.Object);
            ship.Setup(s => s.Wings).Returns((new[] { wing1.Object, wing2.Object }).ToList());

            Assert.Equal(75 * 0.85, _calculations.GetShipWeight(ship.Object));
        }
Exemple #7
0
        public void CheckImploderCombination(int engineId, int weaponId)
        {
            var ship   = ShipFactory.CreateShip();
            var wing   = WingFactory.CreateWing();
            var weapon = WeaponFactory.CreateWeapon();
            var engine = EngineFactory.CreateEngine();

            wing.Setup(w => w.Hardpoint).Returns((new[] { weapon.Object }).ToList());
            ship.Setup(s => s.Wings).Returns((new[] { wing.Object }).ToList());
            ship.Setup(s => s.Engine).Returns(engine.Object);

            engine.Setup(e => e.Id).Returns(engineId);
            weapon.Setup(w => w.Id).Returns(weaponId);

            var valid = Validate(ship, "ImplosionDanger");

            if (engineId == 2 && weaponId == 9)
            {
                Assert.False(valid);
            }
            else
            {
                Assert.True(valid);
            }
        }
        //displays selected entity info
        internal override void Display()
        {
            if (IsActive && ImGui.Begin("Spawn Entity", _flags))
            {
                if (ImGui.Combo("##entityselector", ref _entityindex, _entitytypes, _entitytypes.Length))
                {
                }


                if (_entitytypes[_entityindex] == "Ship")
                {
                    //ImGui.BeginChild("exsistingdesigns");

                    if (_exsistingClasses == null || _exsistingClasses.Count != _uiState.Faction.GetDataBlob <FactionInfoDB>().ShipDesigns.Values.ToList().Count)
                    {
                        _exsistingClasses = _uiState.Faction.GetDataBlob <FactionInfoDB>().ShipDesigns.Values.ToList();
                    }

                    for (int i = 0; i < _exsistingClasses.Count; i++)
                    {
                        string name = _exsistingClasses[i].Name;
                        if (ImGui.Selectable(name))
                        {
                            Entity _spawnedship = ShipFactory.CreateShip(_exsistingClasses[i], _uiState.Faction, _uiState.LastClickedEntity.Entity, _uiState.SelectedSystem, Guid.NewGuid().ToString());
                            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(_spawnedship);
                            //_uiState.SelectedSystem.SetDataBlob(_spawnedship.ID, new TransitableDB());
                            //var rp1 = NameLookup.GetMaterialSD(game, "LOX/Hydrocarbon");
                            //StorageSpaceProcessor.AddCargo(_spawnedship.GetDataBlob<CargoStorageDB>(), rp1, 15000);
                        }
                    }

                    //ImGui.EndChild();
                }
            }
        }
        public void UnregisterObserverTest()
        {
            IStarShip        ship             = ShipFactory.CreateShip(ShipType.Fighter, ShipConfigurationType.Balanced);
            AttackAggregator attackAggregator = new AttackAggregator();

            attackAggregator.RegisterObserver(ship);
            attackAggregator.UnregisterObserver(ship);
            Assert.Equal(0, attackAggregator.Observers.Count());
        }
Exemple #10
0
        public void CreateShip_WhenOneDimensionShipIsValid_ReturnsCorrectShip(OneDimensionShip oneDimensionShip, Ship expectedShip)
        {
            // Arrange
            var sutShipFactory = new ShipFactory();

            // Act
            var result = sutShipFactory.CreateShip(oneDimensionShip);

            // Assert
            result.Should().Be(expectedShip);
        }
Exemple #11
0
        public void TakeDamagHealthZeroTest()
        {
            IStarShip    starShip     = ShipFactory.CreateShip(ShipType.Fighter, ShipConfigurationType.Light);
            int          damageAmount = 9000;
            AttackResult attackResult = new AttackResult {
                Damage = damageAmount
            };

            starShip.TakeDamage(attackResult);
            Assert.Equal(0, starShip.Health);
        }
Exemple #12
0
        public Game(IBoardDimension size)
        {
            this.board = new Board(size);

            Ships = new List <Ship>();
            Ships.Add(ShipFactory.CreateShip(ShipFactory.ShipType.Battleship, "HMS Barham"));
            Ships.Add(ShipFactory.CreateShip(ShipFactory.ShipType.Destroyer, "Hobart-class destroyer"));
            Ships.Add(ShipFactory.CreateShip(ShipFactory.ShipType.Destroyer, "Kashin-class destroyer"));

            AddShipsToBoard(Ships, size.Width, size.Height);
        }
Exemple #13
0
        public void CreateFrigetLightConfigurationCollectionCountTest()
        {
            IStarShip          ship   = ShipFactory.CreateShip(ShipType.Friget, null);
            IShipConfiguration config = ShipConfigurationFactory.CreateShipConfiguration(ShipType.Friget, ShipConfigurationType.Light);

            Assert.True(config.attackImplements.Count() > 0);
            Assert.True(config.defendImplements.Count() > 0);
            Assert.True(config.upgradeImplements.Count() > 0);
            Assert.True(config.attackImplements.Sum(x => x.Size) <= ship.NumberOfAttackSlots);
            Assert.True(config.defendImplements.Sum(x => x.Size) <= ship.NumberOfDefendSlots);
            Assert.True(config.upgradeImplements.Sum(x => x.Size) <= ship.NumberOfUpgradeSlots);
        }
        public void CreateShipConfigurationFrigetHeavyTest()
        {
            IStarShip ship = ShipFactory.CreateShip(ShipType.Friget, ShipConfigurationType.Heavy);

            Assert.True(ship.Armor != 0);
            Assert.True(ship.Speed != 0);
            Assert.True(ship.Health != 0);
            Assert.True(ship.Power != 0);
            Assert.True(ship.NumberOfAttackSlotsAvailable >= 0);
            Assert.True(ship.NumberOfDefendSlotsAvailable >= 0);
            Assert.True(ship.NumberOfUpgradeSlotsAvailable >= 0);
        }
        public void CreateShipConfigurationDestroyerLightTest()
        {
            IStarShip ship = ShipFactory.CreateShip(ShipType.Destroyer, ShipConfigurationType.Light);

            Assert.True(ship.Armor != 0);
            Assert.True(ship.Speed != 0);
            Assert.True(ship.Health != 0);
            Assert.True(ship.Power != 0);
            Assert.True(ship.NumberOfAttackSlotsAvailable >= 0);
            Assert.True(ship.NumberOfDefendSlotsAvailable >= 0);
            Assert.True(ship.NumberOfUpgradeSlotsAvailable >= 0);
        }
Exemple #16
0
        public void StarShipTest()
        {
            IStarShip ship = ShipFactory.CreateShip(ShipType.Fighter, ShipConfigurationType.Heavy);

            Assert.True(ship.availableAttackImplements.Count > 0);
            Assert.True(ship.AttackImplements.Count > 0);
            Assert.True(ship.DefendImplements.Count > 0);
            Assert.True(ship.UpgradeImplements.Count > 0);
            Assert.True(ship.NumberOfAttackSlotsAvailable == ship.NumberOfAttackSlots - ship.AttackImplements.Sum(x => x.Size));
            Assert.True(ship.NumberOfDefendSlotsAvailable == ship.NumberOfDefendSlots - ship.DefendImplements.Sum(x => x.Size));
            Assert.True(ship.NumberOfUpgradeSlotsAvailable == ship.NumberOfUpgradeSlots - ship.UpgradeImplements.Sum(x => x.Size));
        }
Exemple #17
0
        public void CreateShip_WhenOneDimensionShipIsNull_ThrowsArgumentNullException()
        {
            // Arrange
            var sutShipFactory = new ShipFactory();
            OneDimensionShip oneDimensionShip = null;

            // Act
            Action action = () => sutShipFactory.CreateShip(oneDimensionShip);

            // Assert
            action.Should().ThrowExactly <ArgumentNullException>();
        }
        public void NotifyObserversTest()
        {
            IStarShip ship             = ShipFactory.CreateShip(ShipType.Fighter, ShipConfigurationType.Balanced);
            int       oHandA           = ship.Health + ship.Armor;
            var       attackAggregator = new AttackAggregator();

            attackAggregator.RegisterObserver(ship);
            attackAggregator.NotifyObservers(new AttackResult {
                Damage = 10
            });
            Assert.Equal(ship.Health + ship.Armor + 10, oHandA);
            attackAggregator.UnregisterObserver(ship);
        }
Exemple #19
0
        public void TakeDamageTest()
        {
            IStarShip    starShip     = ShipFactory.CreateShip(ShipType.Fighter, ShipConfigurationType.Light);
            var          oHealth      = starShip.Health;
            int          damageAmount = starShip.Armor + 20;
            AttackResult attackResult = new AttackResult {
                Damage = damageAmount
            };

            starShip.TakeDamage(attackResult);
            Assert.Equal(oHealth - 20, starShip.Health);
            Assert.Equal(0, starShip.Armor);
        }
Exemple #20
0
        public void CreateClassAndShip()
        {
            Entity     faction    = FactionFactory.CreateFaction(_game, "Terran");
            StarSystem starSystem = new StarSystem(_game, "Sol", -1);

            string shipClassName = "M6 Corvette";       //X Universe ;3
            string shipName      = "USC Winterblossom"; //Still X Universe

            var requiredDataBlobs = new List <Type>()
            {
                typeof(ShipInfoDB),
                typeof(ArmorDB),
                typeof(BeamWeaponsDB),
                typeof(BuildCostDB),
                typeof(CargoStorageDB),
                typeof(CrewDB),
                typeof(DamageDB),
                typeof(HangerDB),
                typeof(IndustryDB),
                typeof(MaintenanceDB),
                typeof(MissileWeaponsDB),
                typeof(PowerDB),
                typeof(PropulsionDB),
                typeof(SensorProfileDB),
                typeof(SensorsDB),
                typeof(ShieldsDB),
                typeof(TractorDB),
                typeof(TroopTransportDB),
                typeof(NameDB)
            };

            Entity     shipClass       = ShipFactory.CreateNewShipClass(_game, faction, shipClassName);
            ShipInfoDB shipClassInfo   = shipClass.GetDataBlob <ShipInfoDB>();
            NameDB     shipClassNameDB = shipClass.GetDataBlob <NameDB>();

            //Assert.IsTrue(HasAllRequiredDatablobs(shipClass, requiredDataBlobs), "ShipClass Entity doesn't contains all required datablobs");
            Assert.IsTrue(shipClassInfo.ShipClassDefinition == Guid.Empty, "Ship Class ShipInfoDB must have empty ShipClassDefinition Guid");
            Assert.IsTrue(shipClassNameDB.GetName(faction) == shipClassName);

            /////Ship/////
            Vector4    pos        = new Vector4(0, 0, 0, 0);
            Entity     ship       = ShipFactory.CreateShip(shipClass, starSystem.SystemManager, faction, pos, starSystem, shipName);
            ShipInfoDB shipInfo   = ship.GetDataBlob <ShipInfoDB>();
            NameDB     shipNameDB = ship.GetDataBlob <NameDB>();

            //Assert.IsTrue(HasAllRequiredDatablobs(ship, requiredDataBlobs), "Ship Entity doesn't contains all required datablobs");
            Assert.IsTrue(shipInfo.ShipClassDefinition == shipClass.Guid, "ShipClassDefinition guid must be same as ship class entity guid");
            Assert.IsTrue(shipNameDB.GetName(faction) == shipName);
        }
Exemple #21
0
        public ShipPlacement PlaceShip(PlaceShip shipLocation)
        {
            if (!IsPositionWithingBoard(shipLocation.Coordinate))
            {
                return(ShipPlacement.OutOfBoundary);
            }

            IShip newShip = ShipFactory.CreateShip(shipLocation.ShipType);

            return(shipLocation.Direction switch
            {
                ShipDirection.Down => PlaceShipWhenRightOrDown(shipLocation, newShip),
                ShipDirection.Up => PlaceShipWhenLeftOrUp(shipLocation, newShip),
                ShipDirection.Left => PlaceShipWhenLeftOrUp(shipLocation, newShip),
                _ => PlaceShipWhenRightOrDown(shipLocation, newShip),
            });
Exemple #22
0
        public void CheckAtLeastOneWeaponPerWing()
        {
            var ship = ShipFactory.CreateShip();
            var wing = WingFactory.CreateWing();

            wing.Setup(w => w.Hardpoint).Returns((Array.Empty <Weapon>()).ToList());
            ship.Setup(s => s.Wings).Returns((new[] { wing.Object }).ToList());

            Assert.False(Validate(ship, "AtLeastOneWeaponPerWing"));

            var weapon = WeaponFactory.CreateWeapon();

            wing.Setup(w => w.Hardpoint).Returns((new[] { weapon.Object }).ToList());

            Assert.True(Validate(ship, "AtLeastOneWeaponPerWing"));
        }
Exemple #23
0
        public void AttackEnemyShipsTest()
        {
            IStarShip myship               = ShipFactory.CreateShip(ShipType.Fighter, ShipConfigurationType.Light);
            IFleet    enemyfleet           = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.WeekShipsFirst);
            var       oTotalHealthAndArmor = enemyfleet.StarShips.Sum(x => x.Health) + enemyfleet.StarShips.Sum(x => x.Armor);

            //has random miss rate
            for (int i = 0; i < 100; i++)
            {
                myship.Attack(enemyfleet, BattleStratageyType.WeekShipsFirst);
            }

            var newTotalHealthAndArmor = enemyfleet.StarShips.Sum(x => x.Health) + enemyfleet.StarShips.Sum(x => x.Armor);
            var shipsDestroyed         = enemyfleet.StarShips.Where(x => x.Health == 0).ToList();

            Assert.True(oTotalHealthAndArmor > newTotalHealthAndArmor);
        }
        public void ShieldBoosterDecorateShipTest()
        {
            IStarShip ship    = ShipFactory.CreateShip(ShipType.Fighter, null);
            var       oSpeed  = ship.Speed;
            var       oHealth = ship.Health;
            var       oPower  = ship.Power;
            var       oArmor  = ship.Armor;

            var newImplement = DefendImplementFactory.CreateDefendImplement(DefendImplementType.ShieldBooster);

            DefendImplementDecorator.DecorateShip(ship, newImplement);

            Assert.True(ship.Speed == (oSpeed + newImplement.ShipSpeedModification) || ship.Speed == 0);
            Assert.True(ship.Health == (oHealth + newImplement.ShipHealthModification) || ship.Health == 0);
            Assert.True(ship.Power == (oPower + newImplement.ShipPowerModification) || ship.Power == 0);
            Assert.True(ship.Armor == (oArmor + newImplement.ShipArmorModification) || ship.Armor == 0);
            Assert.Equal(1, ship.DefendImplements.Count());
        }
Exemple #25
0
        public void CheckKineticEnergyOnlyOneWingLessThen35()
        {
            var ship = ShipFactory.CreateShip();
            var wing = WingFactory.CreateWing();

            var weapon = WeaponFactory.CreateWeapon();

            weapon.Setup(w => w.DamageType).Returns(DamageTypeEnum.Kinetic);

            wing.Setup(w => w.Hardpoint).Returns((new[] { weapon.Object }).ToList());
            ship.Setup(s => s.Wings).Returns((new[] { wing.Object }).ToList());

            weapon.Setup(w => w.EnergyDrain).Returns(35);
            Assert.False(Validate(ship, "KineticDifference"));

            weapon.Setup(w => w.EnergyDrain).Returns(34);
            Assert.True(Validate(ship, "KineticDifference"));
        }
Exemple #26
0
        public void PlasmaCannonDecorateShipTest()
        {
            IStarShip ship    = ShipFactory.CreateShip(ShipType.Fighter, null);
            var       oSpeed  = ship.Speed;
            var       oHealth = ship.Health;
            var       oPower  = ship.Power;
            var       oArmor  = ship.Armor;

            var newImplement = AttackImplementFactory.CreateAttackImplement(AttackImplementType.PlasmaCannon);

            AttackImplementDecorator.DecorateShip(ship, newImplement);

            Assert.True(ship.Speed == (oSpeed + newImplement.ShipSpeedModification) || ship.Speed == 0);
            Assert.True(ship.Health == (oHealth + newImplement.ShipHealthModification) || ship.Health == 0);
            Assert.True(ship.Power == (oPower + newImplement.ShipPowerModification) || ship.Power == 0);
            Assert.True(ship.Armor == (oArmor + newImplement.ShipArmorModification) || ship.Armor == 0);
            Assert.Equal(1, ship.AttackImplements.Count());
        }
Exemple #27
0
        public void MineFieldDecorateToLargeShipTest()
        {
            IStarShip ship    = ShipFactory.CreateShip(ShipType.Fighter, null);
            var       oSpeed  = ship.Speed;
            var       oHealth = ship.Health;
            var       oPower  = ship.Power;
            var       oArmor  = ship.Armor;

            var newImplement = UpgradeImplementFactory.CreateUpgradeImplement(UpgradeImplementType.MineField);

            UpgradeImplementDecorator.DecorateShip(ship, newImplement);

            Assert.True(ship.Speed == oSpeed);
            Assert.True(ship.Health == oHealth);
            Assert.True(ship.Power == oPower);
            Assert.True(ship.Armor == oArmor);
            Assert.Equal(0, ship.UpgradeImplements.Count());
        }
Exemple #28
0
        public void WarpDriveDecorateShipTest()
        {
            IStarShip ship    = ShipFactory.CreateShip(ShipType.Fighter, null);
            var       oSpeed  = ship.Speed;
            var       oHealth = ship.Health;
            var       oPower  = ship.Power;
            var       oArmor  = ship.Armor;

            var newImplement = UpgradeImplementFactory.CreateUpgradeImplement(UpgradeImplementType.WarpDrive);

            UpgradeImplementDecorator.DecorateShip(ship, newImplement);

            Assert.True(ship.Speed == (oSpeed + newImplement.ShipSpeedModification) || ship.Speed == 0);
            Assert.True(ship.Health == (oHealth + newImplement.ShipHealthModification) || ship.Health == 0);
            Assert.True(ship.Power == (oPower + newImplement.ShipPowerModification) || ship.Power == 0);
            Assert.True(ship.Armor == (oArmor + newImplement.ShipArmorModification) || ship.Armor == 0);
            Assert.Equal(1, ship.UpgradeImplements.Count());
        }
Exemple #29
0
        public void CreateShip_WhenOneDimensionShipLengthIsZeroOrNegative_ThrowsArgumentException(int shipLength)
        {
            // Arrange
            var sutShipFactory   = new ShipFactory();
            var oneDimensionShip = new OneDimensionShip()
            {
                Length = shipLength
            };

            // Act
            Action action = () => sutShipFactory.CreateShip(oneDimensionShip);

            // Assert
            var expectedErrorMessage = $"The {nameof(OneDimensionShip.Length)} of {nameof(OneDimensionShip)} argument is zero or negative.";

            action.Should().ThrowExactly <ArgumentException>()
            .And.Message.Should().Be(expectedErrorMessage);
        }
Exemple #30
0
        public void CreateShip_WhenOneDimensionShipLengthHasANegativeComponent_ThrowsArgumentException(Position position)
        {
            // Arrange
            var sutShipFactory   = new ShipFactory();
            var oneDimensionShip = new OneDimensionShip()
            {
                Length = 1, StartPosition = position
            };

            // Act
            Action action = () => sutShipFactory.CreateShip(oneDimensionShip);

            // Assert
            var expectedErrorMessage = $"{nameof(OneDimensionShip.StartPosition)} of {nameof(OneDimensionShip)} argument cannot have a negative coordinate.";

            action.Should().ThrowExactly <ArgumentException>()
            .And.Message.Should().Be(expectedErrorMessage);
        }