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 SetFormationRow_ValidInput_SetShipRowWithSpecifiedQuantity()
        {
            using (var mock = AutoMock.GetLoose())
            {
                //Arrange
                BattleFormation formation = new BattleFormation("formation 1");
                var             ship      = Battleship.CreateBattleship("Reven");
                //var shipMock = mock.Mock<Ship>();
                //var ship = shipMock.Object;
                //Act
                formation.SetFormationRow(ship, 100, 2);

                //Assert
                Assert.AreSame(formation.Rows[2].SelectedShip, ship);
            }
        }
Exemple #3
0
        public void SetFormation_InvalidInput_SetsRowWithSpecifiedQuntaty()
        {
            using (var mock = AutoMock.GetLoose())
            {
                //Arrange

                BattleFormation battleFormation = new BattleFormation("Foramtion 1");
                //var raven = Battleship.CreateBattleship("Raven");
                var shipmock = mock.Mock <Ship>();

                var ship = shipmock.Object;
                //Act
                battleFormation.SetFormationRow(ship, 2000, 4);

                //Assert
                Assert.AreSame(battleFormation.Rows[4].SelectedShip, ship);
            }
        }
Exemple #4
0
        public void SetFormation_GivenInvalidRowPosition_ThrowException()
        {
            using (var mock = AutoMock.GetLoose())
            {
                BattleFormation battleFormation = new BattleFormation("Foramtion 2");
                //var raven = Battleship.CreateBattleship("Raven");
                var shipmock = mock.Mock <Ship>();

                var ship = shipmock.Object;
                //Act
                // battleFormation.SetFormationRow(ship, 2000, 7);

                //Assert
                Assert.Multiple(() =>
                {
                    var ex = Assert.Catch <Exception>(() => battleFormation.SetFormationRow(ship, 200, 7),
                                                      "Expected exception is missing");
                    Assert.AreEqual("Invalid Row Position", ex.Message, "Wrong error message");
                });
            }
        }