Exemplo n.º 1
0
        /// <summary>
        /// Creates a new battleship either manually or authomatically finding ther largest empty slot
        /// </summary>
        /// <param name="random"></param>
        /// <param name="alingment"></param>
        /// <param name="size"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public Battleship CreateBattleship(bool random, Alingment alingment = Alingment.Horizontal, int size = -1, int x = -1, int y = -1)
        {
            Battleship bs;

            if (random)      //if random find the largest Battleship that we can allocate to the board
            {
                if (alingment == Alingment.Horizontal)
                {
                    bs = FindLargestHorizontalShip();
                }
                else
                {
                    bs = FindLargestVerticalShip();
                }
            }
            else
            {
                bs = BuildBattleship(alingment, size, x, y);
            }
            if (bs != null)
            {
                Battleships.Add(bs);
            }
            return(bs);
        }
Exemplo n.º 2
0
        public void AddBattleship(Battleship battleShip)
        {
            // check if battleship can be added in this plain
            if (!(battleShip.Positions.First().X == 0 && battleShip.Positions.Last().X == Xaxis - 1) &&
                !(battleShip.Positions.First().Y == 0 && battleShip.Positions.Last().Y == Yaxis - 1))
            {
                throw new ArgumentOutOfRangeException(nameof(battleShip), "Battleship is out of the bounds of plain");
            }

            Battleships.Add(battleShip);
        }