/// <summary> /// Initializes a new instance of the <see cref="BaseBattleShip"/> class. /// </summary> /// <param name="shipType">Type of the ship.</param> /// <param name="_MissleHitResistenceCapacity">The missle hit resistence capacity.</param> public BaseBattleShip(BattleshipType shipType, int _MissleHitResistenceCapacity = 1) { TypeOfBattleship = shipType; MissleHitResistenceCapacity = _MissleHitResistenceCapacity; HitCounter = 0; // SafeBattleShipCoordinates = GetOccupiedCoordinates(); shipCoordinatesHitCapacity = new Dictionary <Point, int>(); }
/// <summary> /// Prepares the ships for player. /// </summary> /// <param name="shipType">Type of the ship.</param> /// <param name="shipDimensions">The ship dimensions.</param> /// <param name="shipPositions">The ship positions.</param> /// <returns></returns> /// <exception cref="Exception">Invalid Ship Length</exception> private static IEnumerable <BaseBattleShip> prepareShipsForPlayer(BattleshipType shipType, Point shipDimensions, string shipPositions) { BaseBattleShip ship = null; List <BaseBattleShip> shipFleet = new List <BaseBattleShip>(); if (shipPositions.Length % 2 != 0) // even length { throw new Exception("Invalid Ship Length"); } var numberOfShips = shipPositions.Length / 2; for (int i = 0; i < shipPositions.Length; i = i + 2) // looking for ship dimensions { // create Ship switch (shipType) { case BattleshipType.P: ship = new BattleshipTypeP(); break; case BattleshipType.Q: ship = new BattleshipTypeQ(); break; default: break; } ship.Width = shipDimensions.X; ship.Height = shipDimensions.Y; ship.PlacementLocation = new Point( Convert.ToInt32(Enum.Parse(typeof(XCoordinate), shipPositions[i + 1].ToString())), Convert.ToInt32(Enum.Parse(typeof(YCoordinate), shipPositions[i].ToString())) ); shipFleet.Add(ship); } return(shipFleet); }