Example #1
0
        static void Main(string[] args)
        {
            double number1 = 20.0;
            double number2 = 66.0;

            ShipsFactory _shipFactory = new ShipsFactory();
            int          n            = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                AbstractShips _cargoShip = _shipFactory.GetShip("Cargo");
                if (_cargoShip != null)
                {
                    _cargoShip.Build(number1, number2);
                }
                number1 += 1.0;
                number2 += 1.0;
            }

            for (int i = 0; i < n; i++)
            {
                AbstractShips _destroyerShip = _shipFactory.GetShip("Destroyer");
                if (_destroyerShip != null)
                {
                    _destroyerShip.Build(number1, number2);
                }
                number1 += 1.0;
                number2 += 1.0;
            }

            Console.ReadLine();
        }
        private void Start()
        {
            Servicer.Provide((IRoutineRunner)RoutineRunner.Create());
            Servicer.Provide((IEntityFactory) new EntityFactory());
            _factory = new ShipsFactory(_shipsFactoryContext);

            Reload();
        }
Example #3
0
        public void WhenShipIsHitThenShipHitsCounterIsIncreased()
        {
            IShip ship         = ShipsFactory.CreateDestroyerShip();
            int   startingHits = ship.Hits;

            ship.Shoot();

            Assert.AreEqual(startingHits + 1, ship.Hits, "Shooting to ship should increase hits number");
        }
Example #4
0
        public void CheckCreateFleepZeroShip()
        {
            ShipsFactory shipsFactory = new ShipsFactory();
            FleetConfig  fleetConfig  = new FleetConfig();
            List <Ship>  shipsList;

            shipsList = shipsFactory.GetFleet(fleetConfig);
            Assert.AreEqual(0, shipsList.Count);
        }
Example #5
0
        public void WhenAllShipsAreSunkThenGameEnds()
        {
            var size = ShipsFactory.CreateBattleShip().Size;

            Assert.AreEqual(ShootResult.Sunk, ShootHorizontally("A", 1, size));
            Assert.AreEqual(ShootResult.Sunk, ShootHorizontally("C", 1, size));
            Assert.AreEqual(ShootResult.Sunk, ShootHorizontally("E", 1, size));
            Assert.AreEqual(ShootResult.Sunk, ShootHorizontally("G", 1, size));
            Assert.AreEqual(ShootResult.Won, ShootHorizontally("I", 1, size));
        }
Example #6
0
        public void ColonizerGetColonists_ParamIsLowerThanColonistsOnShip_GetColonists()
        {
            ShipsFactory ships = new ShipsFactory(new Resources(double.MaxValue, double.MaxValue, double.MaxValue));

            Colonizer colonizer = ships.GetColonizer();

            double colonize = colonizer.GetColonists(colonizer.ColonistsOnShip / 4);

            Assert.True(colonize == (Colonizer.Colonists / 4));
        }
Example #7
0
        public void ColonizerGetColonists_ParamIsGreaterThanColonistsOnShip_GetColonists()
        {
            ShipsFactory ships = new ShipsFactory(new Resources(double.MaxValue, double.MaxValue, double.MaxValue));

            Colonizer colonizer = ships.GetColonizer();

            double colonize = colonizer.GetColonists(colonizer.ColonistsOnShip * 4);

            Assert.Zero(colonize);
        }
Example #8
0
        public void CheckCreateNineShipsToFleepShip()
        {
            ShipsFactory shipsFactory = new ShipsFactory();
            FleetConfig  fleetConfig  = new FleetConfig();
            List <Ship>  shipsList;

            fleetConfig.OneMastShipCount   = 4;
            fleetConfig.TwoMastShipCount   = 3;
            fleetConfig.ThreeMastShipCount = 2;
            shipsList = shipsFactory.GetFleet(fleetConfig);
            Assert.AreEqual(9, shipsList.Count);
        }
Example #9
0
        public void CannotHitSunkShip()
        {
            IShip ship = ShipsFactory.CreateDestroyerShip();

            for (int i = 0; i < ship.Size; i++)
            {
                ship.Shoot();
            }

            Assert.Throws <InvalidOperationException>(
                () => ship.Shoot(),
                "It shouldn't be possible to hit already sunk ship.");
        }
        public void CannotAddMoreShipsThanInSettings()
        {
            var ships = new List <IShip>()
            {
                ShipsFactory.CreateBattleShip(),
                ShipsFactory.CreateBattleShip(),
                ShipsFactory.CreateBattleShip()
            };

            Assert.Throws <InvalidOperationException>(
                () => _playerValidator.ValidateNumberOfPlacedShips(ShipsFactory.CreateBattleShip(), ships),
                "It shouldn't be possible to add more ships than in settings");
        }
Example #11
0
        public void MinerGetMiners_CanAffordMiners_ReturnMinersQuantity()
        {
            int shipsToBuy            = 10;
            int resourcesInitModifier = 10;

            Resources inPossesion = new Resources(MinerFleet.ShipPrice);

            inPossesion.Multiply(resourcesInitModifier);

            ShipsFactory ships = new ShipsFactory(inPossesion);

            int result = ships.GetMiners(shipsToBuy);

            Assert.AreEqual(shipsToBuy, result);
        }
        public void CanPlaceShipOnBoard(string coordinate, Direction direction, bool isValid)
        {
            IShip ship = ShipsFactory.CreateBattleShip();

            if (isValid)
            {
                Assert.DoesNotThrow(() =>
                                    _gameBoard.SetShip(new ShipLocation(ship, Coordinate.Create(coordinate), direction)),
                                    $"It is not possible to setup ship on {coordinate}, with direction {direction}, with ship width {ship.Size}");
                Assert.Pass("All conditions passed");
            }

            Assert.Throws <InvalidOperationException>(() =>
                                                      _gameBoard.SetShip(new ShipLocation(ship, Coordinate.Create(coordinate), direction)),
                                                      $"It is possible to setup ship on {coordinate}, with direction {direction}, with ship width {ship.Size}, but shouldn't be");
        }
Example #13
0
        public void SetUp()
        {
            GameSettings.Instance.SetNumberOfShips(numberOfBattleships: 5, numberOfDestroyerShips: 1);

            _game = GameBuilderDirector
                    .NewGame
                    .AddPlayer(new Core.Game.Players.Player(Player1))
                    .AddShip(ShipsFactory.CreateBattleShip())
                    .WithCoordinatesStartingAt("A1")
                    .AndDirection(Direction.Vertical)
                    .AddShip(ShipsFactory.CreateBattleShip())
                    .WithCoordinatesStartingAt("A3")
                    .AndDirection(Direction.Vertical)
                    .AddShip(ShipsFactory.CreateBattleShip())
                    .WithCoordinatesStartingAt("A5")
                    .AndDirection(Direction.Vertical)
                    .AddShip(ShipsFactory.CreateBattleShip())
                    .WithCoordinatesStartingAt("A7")
                    .AndDirection(Direction.Vertical)
                    .AddShip(ShipsFactory.CreateBattleShip())
                    .WithCoordinatesStartingAt("A9")
                    .AndDirection(Direction.Vertical)
                    .AddPlayer(new Core.Game.Players.Player(Player2))
                    .AddShip(ShipsFactory.CreateBattleShip())
                    .WithCoordinatesStartingAt("A1")
                    .AndDirection(Direction.Horizontal)
                    .AddShip(ShipsFactory.CreateBattleShip())
                    .WithCoordinatesStartingAt("C1")
                    .AndDirection(Direction.Horizontal)
                    .AddShip(ShipsFactory.CreateBattleShip())
                    .WithCoordinatesStartingAt("E1")
                    .AndDirection(Direction.Horizontal)
                    .AddShip(ShipsFactory.CreateBattleShip())
                    .WithCoordinatesStartingAt("G1")
                    .AndDirection(Direction.Horizontal)
                    .AddShip(ShipsFactory.CreateBattleShip())
                    .WithCoordinatesStartingAt("I1")
                    .AndDirection(Direction.Horizontal)
                    .Start();
        }
Example #14
0
        public void CanBuildValidGame()
        {
            GameSettings.Instance.SetNumberOfShips(numberOfBattleships: 1, numberOfDestroyerShips: 4);

            var game = GameBuilderDirector
                       .NewGame
                       .AddPlayer(new Core.Game.Players.Player(Player1))
                       .AddShip(ShipsFactory.CreateDestroyerShip())
                       .WithCoordinatesStartingAt("A1")
                       .AndDirection(Direction.Vertical)
                       .AddShip(ShipsFactory.CreateDestroyerShip())
                       .WithCoordinatesStartingAt("A2")
                       .AndDirection(Direction.Vertical)
                       .AddPlayer(new Core.Game.Players.Player(Player2))
                       .AddShip(ShipsFactory.CreateDestroyerShip())
                       .WithCoordinatesStartingAt("A1")
                       .AndDirection(Direction.Vertical)
                       .AddShip(ShipsFactory.CreateDestroyerShip())
                       .WithCoordinatesStartingAt("A2")
                       .AndDirection(Direction.Vertical)
                       .Start();

            Assert.IsNotNull(game);
        }
Example #15
0
 public void SetupNewFactory(int size)
 {
     _shipsFactory = new ShipsFactory(size);
 }