Ejemplo n.º 1
0
        public static Battleship BuildBattleShip(Coordinate[] coordinates)
        {
            if (coordinates == null)
            {
                throw new ArgumentNullException(nameof(coordinates));
            }
            if (coordinates.Length == 0)
            {
                throw new ArgumentOutOfRangeException($"A battleship can not be of zero length.");
            }

            var battleshipSize    = coordinates.Length;
            var battleshipSquares = new BattleshipSquare[battleshipSize];
            var counter           = 0;

            foreach (var coord in coordinates)
            {
                var bPart = new BattleshipSquare(coord);

                battleshipSquares[counter] = bPart;
                counter++;
            }

            var battleship = new Battleship(battleshipSquares);

            return(battleship);
        }
Ejemplo n.º 2
0
 public void LinkBattleship(Battleship battleship)
 {
     if (battleship == null)
     {
         throw new ArgumentNullException(nameof(battleship));
     }
     Battleship = battleship;
 }
        /// <summary>
        /// Links all BattleshipSquares to its respective SeaSquare
        /// </summary>
        /// <param name="battleship"></param>
        public void PositionBattleship(Battleship battleship)
        {
            if (battleship == null)
            {
                throw new ArgumentNullException(nameof(battleship));
            }

            var current = battleship.First;

            while (current != null)
            {
                var battleshipCoord = current.Value.Coordinate;
                var seaSquare       = GetSeaSquare(_board, battleshipCoord);

                seaSquare.LinkBattleshipSquare(current.Value);
                seaSquare.LinkBattleship(battleship);
                current = current.Next;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a battleship square to the sea square to track opponents pieces
        /// </summary>
        /// <param name="battleshipSquare"></param>
        public void AddBattleshipSquare(BattleshipSquare battleshipSquare)
        {
            if (battleshipSquare == null)
            {
                throw new ArgumentNullException(nameof(battleshipSquare));
            }

            BattleshipSquare = battleshipSquare;

            if (HasBattleship)
            {
                Battleship.AddBattleshipPart(battleshipSquare);
            }
            else
            {
                var battleship = new Battleship(new BattleshipSquare[] { battleshipSquare });
                Battleship = battleship;
            }
        }
 /// <summary>
 /// Make sure there is no conflict with an existing battleship
 /// </summary>
 /// <param name="battleship"></param>
 /// <returns></returns>
 public bool CanAddBattleship(Battleship battleship)
 {
     //TODO: Make sure there is no conflict with an existing battleship
     return(true);
 }