예제 #1
0
        /// <summary>
        /// Check can the ship place his position
        /// </summary>
        /// <param name="checkShip">Ship for check</param>
        /// <returns>true - if can place ship, otherwise - false</returns>
        private bool CheckShips(Ship checkShip)
        {
            if ((checkShip.Orientation == ShipOrientation.Horisontal) && (11 - checkShip.StartPosition.Y < checkShip.Size))
            {
                return(false);
            }
            if ((checkShip.Orientation == ShipOrientation.Vertical) && (11 - checkShip.StartPosition.X < checkShip.Size))
            {
                return(false);
            }

            foreach (Ship ship in Ships)
            {
                if (Ship.GetShipArea(ship).Any(checkShip.IsLocated))
                {
                    return(false);
                }
            }

            return(true);
        }