Ejemplo n.º 1
0
        private bool CheckShipCompletelyDestroyed(int x, int y)
        {
            // если по указанным координатам (x;y) есть соседняя целая палуба
            // значит корабль еще НЕ полностью разрушен
            if (null != CheckNearestCell(Ceil.Ship, x, y))
            {
                return(false);
            }

            var pair = CheckNearestCell(Ceil.Injured, x, y);

            if (null != pair)
            {
                var i         = pair.Item1;
                var j         = pair.Item2;
                var direction = DirectionMethods.GetDirectionByPoints(x, y, i, j);

                var result = CheckNeighborsByDirection(direction, x, y);
                if (null != result)
                {
                    return((bool)result);
                }

                direction = direction.Invert();

                result = CheckNeighborsByDirection(direction, x, y);
                if (null != result)
                {
                    return((bool)result);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        protected virtual void InstallShips(int count, int size)
        {
            for (int counter = 0, x, y; counter < count;)
            {
                x = Constants.RandomGenerator.Next(0, Constants.MapSize);
                y = Constants.RandomGenerator.Next(0, Constants.MapSize);
                var direction = DirectionMethods.GetRandomDirection();

                if (CanInstallShip(direction, size, x, y))
                {
                    InstallShip(direction, size, x, y);
                    ++counter;
                }
            }
        }